我想使用Postal(http://aboutcode.net/postal/)从模板视图生成电子邮件。我们在混合MVC和WebForms应用程序中使用它。
我正在尝试使用Postal生成MailMessage,然后应用一些旧的自定义逻辑并发送它们。
我正在使用EmailService.CreateMailMessage,它适用于普通的html电子邮件,只要我在我的视图中使用@Html或@Url,就会出现这样的异常:
无法编译模板。名称' Url'在当前背景下不存在。
以下是一些代码:
dynamic email = new Email("ForgotPassword");
email.To = "..."; // removed email here
email.Subject = "Forgot your password";
var service = Factory.Get<IEmailService>();
var msg = service.CreateMailMessage(email);
我们也使用Ninject作为我们的依赖注入框架,我定义了这个:
Bind<IEmailService>().ToMethod(x => new EmailService(new ViewEngineCollection {new FileSystemRazorViewEngine(HostingEnvironment.MapPath("~/Views/Emails"))}));
可能我没有正确设置,但我不知道到底是什么。
谢谢,
答案 0 :(得分:1)
这对我来说是一种失败,但如果有人在将来犯同样的错误,我会发布一个答案。我尝试按照这些说明在asp.net上运行Postal:http://aboutcode.net/postal/outside-aspnet.html,但由于我已经在asp.net中,我只是直接使用EmailService而不用ViewEngineCollection初始化它。