Create email using ASP.NET MVC views
During development you want to iterate quickly and don’t want to send
out a new mail each time you’ve made some changes to a template. That’s
where EmailViewResult
comes in. It’s an ActionResult
class that can be
returned from MVC actions, and simply renders your template to the browser.
To get started, just create an action that composes your Email
object like you
would do otherwise. But then, instead of sending it, you just pass it to the EmailViewResult
constructor and return that from the action.
public class PreviewConroller : Controller
{
public ActionResult Example()
{
dynamic email = new Email("Example");
// set up the email ...
return new EmailViewResult(email);
}
}
There are several possible scenarios of what the EmailViewResult
will output:
?format=text
or ?format=html
If the resulting email is an html email and contains embedded images then those images will be inlined in the html as well.