我正在尝试使用以下代码发送电子邮件:
var engines = new ViewEngineCollection();
var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
var eng = new FileSystemRazorViewEngine(viewsPath);
engines.Add(eng);
foreach (var EmailEntry in EmailEntries)
{
IEmailService service = new Postal.EmailService(engines);
var email = new EmailTemplateModel
{
ViewName = "EmailTemplateModel",
FromAddress = "donotreply@email.com",
EmailAddress = EmailEntry,
Subject = "Task Report",
Date = Dates,
Task = DatesAndTasks,
};
service.Send(email);
}
但是当我查看hangfire时,它会显示以下错误:
Microsoft.Practices.ServiceLocation.ActivationException
尝试获取IViewEngine类型的所有实例时发生激活错误 Microsoft.Practices.ServiceLocation.ActivationException:尝试获取IViewEngine类型的所有实例时发生激活错误---> System.ArgumentNullException:值不能为null。 参数名称:httpContext