c# - MvcMailer 可以在类库中使用吗?

标签 c# asp.net-mvc-3 mvcmailer

我想在类库中使用 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/

相关文章:

c# - 领域驱动设计和聚合

c# - 使用 Mvc Mailer 向多个地址发送电子邮件

javascript - AJAX 调用 C# Web 方法以返回列表

c# - 状态 500 : InvalidOperationException: No route matches the supplied values

c# - Xaml C# 绑定(bind)数据仅在第一次有效

jquery - asp.net mvc 3 razor 文件上传

asp.net - 可以更改 RadioButtonFor 的名称吗?

asp.net-mvc - 使用 ViewModel 屏蔽可为 null 的域属性

c# - 发送异步电子邮件

c# - 在 asp.net MVC4 应用程序中使用 MVCMailer,在发送电子邮件时不断出现错误