2

I am using asp.net mvc 3 and quartz scheduler.

Currently I have this

  1. A job gets created and executed.
  2. Goes to a controller where I map domain to view models with automapper
  3. 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).

chobo2
  • 83,322
  • 195
  • 530
  • 832
  • Have you set up your SMTP settings properly? – Brian Driscoll May 18 '11 at 19:28
  • @ Brian Driscoll - Setup to go to a local folder and all my other ones work(ones that a user request a from and contacts my controller where I call up this email controller and send out emails...so the httpcontext is made for me on the first call to the controoler) – chobo2 May 18 '11 at 19:31
  • Was this problem solved? Please provide details. Thanks – Nate Aug 06 '11 at 21:56
  • I got the same problem with ActionMailer, it do not allow to send e-mail if HttpContext do not exists. That a huge limitation! – Tomas Apr 24 '12 at 13:33

1 Answers1

0

The Job execution of Quartz doesn't run in a HttpRequest. Also HttpContext.Current is NULL. It seems that this asp.net mailer doesn't work without the asp.net request environment (hava a look at StackTrace)

checkout Render a view as a string (render view, put into mail and send..), but unfortunately in this post all samples works with the current ControllerContext/HttpContext too.

Community
  • 1
  • 1
benwasd
  • 1,342
  • 10
  • 18
  • Müller - Yes HttpContext is null. I actually got the names mixed up I am using ActionMailer not asp.net mvc mailer. I think both of these email senders suffer from the same problem they need the HttpContext. I am lost on step one. What is that doing? So in my first controller I should put the step one code in? – chobo2 May 18 '11 at 21:27
  • i did this with mvc2, sending asp.net rendered partial views by email in a job. i will post you the code – benwasd May 19 '11 at 07:26
  • how can I use it though if I need the httpContext? – chobo2 May 22 '11 at 00:02