【发布时间】:2011-05-18 19:20:59
【问题描述】:
我正在使用 asp.net mvc 3 和石英调度程序。
目前我有这个
- 创建并执行作业。
- 转到一个控制器,我在其中映射域以使用自动映射器查看模型
- 结果转到我想使用的控制器 Action Mailer
我收到一个错误
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:
// 工作
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);
}
//控制器(做映射)\
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 邮件程序
public EmailResult SendCalendarAppointmentNotifiation(CalendarAppointmentReminderVM vm)
{
To.Add(vm.To);
Subject = String.Format("Subject");
return Email("SendCalendarAppointmentEmail", vm);
}
死在return Email("SendCalendarAppointmentEmail", vm); 我想用它,因为我用它来发送我所有的其他电子邮件,我发现它发送电子邮件的方式要好得多(更容易让它们看起来更好,因为你可以使用母版页和强类型视图)。
【问题讨论】:
-
您的 SMTP 设置是否正确?
-
@ Brian Driscoll - 设置到本地文件夹和我所有其他的工作(用户请求并联系我的控制器的那些我调用这个电子邮件控制器并发送电子邮件.. .so httpcontext 是在第一次调用控制器时为我制作的)
-
这个问题解决了吗?请提供详细信息。谢谢
-
我在 ActionMailer 上遇到了同样的问题,如果 HttpContext 不存在,它就不允许发送电子邮件。这是一个巨大的限制!
标签: c# asp.net-mvc asp.net-mvc-3 quartz-scheduler httpcontext