I want to use MvcMailer in a class library, which would essentially be my one-stop-shop for composing and sending emails for my solution. I thought that that is what MvcMailer was designed for, but it appears it cannot find any of my .cshtml files--I guess it expects them to in my startup project.
Is there any way for MvcMailer to be 100% separate from my other projects?
Thanks.
This is not possible according to MvcMailer documentation https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide (extract below), maybe you can have a separate web project that its only purpose is to send emails and only accept requests from your application
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 :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With