我想在我的网站中提醒我,所以我决定使用石英.net库。 我想在特定时间发送特定电子邮件。 我使用下面的代码
实现了IJob
界面
public class EmailJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
using (var message = new MailMessage("example@gmail.com", "example2@gmail.com"))
{
message.Subject = "Test";
message.Body = "Test at " + DateTime.Now;
using (SmtpClient client = new SmtpClient
{
EnableSsl = true,
Host = "smtp.gmail.com",
Port = 587,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("example@gmail.com", "password")
})
{
client.Send(message);
await Console.Out.WriteLineAsync("HelloJob is executing.");
}
}
}
}
和调度程序是这样的:
public class JobScheduler
{
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
scheduler.Start();
IJobDetail job = JobBuilder.Create<EmailJob>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
)
.Build();
scheduler.ScheduleJob(job, trigger);
}
}
,在Application_start
中,我使用以下代码调用了调度程序:
JobScheduler.Start();
现在,如何查看结果?我的意思是我该如何发送或接收电子邮件? 有人可以帮忙吗?