8

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.

smdrager
  • 7,327
  • 6
  • 39
  • 49

1 Answers1

1

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 :(

jorgehmv
  • 3,633
  • 3
  • 25
  • 39
  • 2
    Thanks for posting. This is a real shame because that's a really desirable feature. I had found a similar post by him saying its not possible but I was wondering if anyone had found a workaround. After wasting a few hours, it seems there is no easy solution. – smdrager Apr 10 '12 at 13:15
  • 3
    It seems as though you can use ActionMailer.Net.Standalone to do this as it uses RazorEngine. As far as I can tell it has no requirement for HttpContext and can be used in an entirely independent process/assembly. – James White Jun 03 '12 at 16:20
  • 1
    Using ActionMailer.Net stand alone: http://geeksharp.com/2011/07/06/actionmailer-0-6-released/ – Eric J. Jul 21 '12 at 04:25