How to build HTML messages in an MVC3 application

2019-05-06 23:11发布

问题:

I was thinking about this during my morning shower, how can I construct HTML messages in an MVC3 application?

I was thinking something like using a PartialView and invoking the resulting HTML, saving the it as a string to use it in the HtmlMessage body.

Instead of doing something like:

string body = @"<html><h1>This is an email. Yuk formatting and hard to maintain.</h1></html>";

I could do something like:

string body = Html.Action("WelcomeEmail", "Emails");

Since MVC3 is so robust and mature, there must be a standard way of doing this, correct?

What is the recommended approach?

回答1:

Postal allows you to send emails as rendered Views



回答2:

I strongly suggest Mvc.Mailer.

You get all of the benefit of the MVC framework along with scaffolding support.