- List item
I am trying to implement Quartz.Net in my project, I have placed two .cs where I declare public classes, however, the code that I incorporate, gives me errors, which I detail below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using Quartz.Listener;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace WEB_Project.Models
{
public class EmailJob : IJob /*Error Line*/
{
public void Execute(IJobExecutionContext context)
{
using (var message = new MailMessage("user@gmail.com", "user@live.co.uk"))
{
message.Subject = "Test";
message.Body = "Test at " + DateTime.Now;
using (SmtpClient client = new SmtpClient
{
EnableSsl = true,
Host = "smtp.gmail.com",
Port = 587,
Credentials = new NetworkCredential("user@gmail.com", "password")
})
{
client.Send(message);
}
}
}
}
}
- In this line, the error appears:
I already tried to place the IJob call in this way: Quartz.IJob, but it does not work either.
In the other .cs, I have the JOB, but it also gives me an error, I explain it below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using Quartz.Impl;
using System.Threading.Tasks;
namespace WEB_Project.Models
{
public class JobScheduler
{
public void Start(DateTime date)
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); /*Error Line*/
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);
}
}
}