I am using asp.net mvc 3 and quartz scheduler.
Currently I have this
- A job gets created and executed.
- Goes to a controller where I map domain to view models with automapper
- Results go to controller where I want to use Action Mailer
I get an error
System.ArgumentNullException was unhandled by user code
Message=Value cannot be null.
Parameter name: httpContext
Source=System.Web
ParamName=httpContext
StackTrace:
at System.Web.Routing.RequestContext..ctor(HttpContextBase httpContext, RouteData routeData)
at ActionMailer.Net.MailerBase.Email(String viewName, Object model, String masterName)
at EmailController.SendCalendarAppointmentNotifiation(CalendarAppointmentReminderVM vm) in EmailController.cs:line 73
at RemindersController.CalendarAppointmentsReminders(List`1 taskReminders) in RemindersController.cs:line 54
at QuartzJobs.AppointmentRemindersJob.Execute(JobExecutionContext context) in AppointmentRemindersJob.cs:line 39
at Quartz.Core.JobRunShell.Run()
InnerException:
// Job
public void Execute(JobExecutionContext context)
{
// some code to do some checking and to get results above(not shown)
RemindersController remindersController = new RemindersController();
remindersController.CalendarAppointmentsReminders(calendarAppointmentReminders);
}
// controller (to do mapping)\
public void CalendarAppointmentsReminders(List<AppointmentReminder> appointments)
{
List<CalendarAppointmentReminderVM> vm = Mapper.Map<List<CalendarAppointment>, List<CalendarAppointmentReminderVM>>(appointments.Select(x => x.CalendarAppointment).ToList());
Mapper.Map<List<AppointmentReminder>, List<CalendarAppointmentReminderVM>>(appointments, vm);
foreach (var v in vm)
{
new EmailController().SendCalendarAppointmentNotifiation(v);
}
}
// mvc mailer
public EmailResult SendCalendarAppointmentNotifiation(CalendarAppointmentReminderVM vm)
{
To.Add(vm.To);
Subject = String.Format("Subject");
return Email("SendCalendarAppointmentEmail", vm);
}
Dies right on return Email("SendCalendarAppointmentEmail", vm);
I want to use this as I am using it to send out all my other emails and I find it alot better way to send emails(easier to make them look nicer as you can use master pages and strongly typed views).