Can MvcMailer be used in a class library?

I want to use MvcMailer in a class library, which essentially would be my general store to compose and send emails for my solution. I thought MvcMailer was developed for this, but it looks like it cannot find any of my .cshtml files - I think it expects them in my launch project.

Is there a way that MvcMailer is 100% separated from my other projects?

Thanks.

+8
c # asp.net-mvc-3 mvcmailer
source share
1 answer

This is not possible according to the MvcMailer documentation https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide (described below), you may have a separate web project that has a single purpose is to send emails and accept applications only from your application

Sending emails from a background process Do you need to send emails from a background process? Yes you are right. You do not want to block the request / response cycle to send this notification. Instead, you want to create a background process that will do this for you, even if it is sent after a short delay. Here is what you can do:

Save the email related data to a database. Create a REST / SOAP web service that will send emails. This ensures that your Mailer gets access to the HttpContext, which is necessary for the normal operation of the main ASP.NET MVC framework. For example, to find your submissions, create URLs and perform authentication / authorization. Create a simple application that calls a web service. This can be a Windows utility application or an executable application running under the Windows Scheduled task. A future version of MvcMailer is likely to support this. But this is difficult due to two reasons:

MailMessage is not Serializable out of the box and has many complex fields and associations. The ASP.NET Framework core still needs an HttpContext :(

+1
source share

All Articles