我想在类库中使用 MvcMailer,这基本上是我为我的解决方案撰写和发送电子邮件的一站式商店。我认为这就是 MvcMailer 的设计目的,但它似乎无法找到我的任何 .cshtml 文件——我猜它希望它们出现在我的启动项目中。
有没有办法让 MvcMailer 与我的其他项目 100% 分开?
谢谢。
最佳答案
根据 MvcMailer 文档这是不可能的 https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide (下面摘录),也许你可以有一个单独的网络项目,它的唯一目的是发送电子邮件并且只接受来自你的应用程序的请求
Email Sending from a Background Process Do you need to send emails from a background process? Yes, you're right. You don't want to block your request/response cycle for that notification email to be sent. Instead, what you want is a background process that does it for you, even if it's sent after a short delay. Here's what you can do:
Save your email related data into a database. Create a REST/SOAP web service that sends out the emails. This will ensure your Mailer has access to the HttpContext, which is essential for the core ASP.NET MVC framework to work properly. For example, to find your views, produce URLs, and perform authentication/authorization. Create a simple App that calls the web service. This could be a windows service app or an executable app running under Windows Scheduled task. A future version of MvcMailer is likely to have support for this. But it is hard because of two reasons:
MailMessage is not Serializable out of the box and has a lot of complex fields and associations. The core ASP.NET framework still needs HttpContext :(
关于c# - MvcMailer 可以在类库中使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10080176/