Create email using ASP.NET MVC views


Install Postal into your ASP.NET web application using Nuget.

PM> Install-Package Postal.Mvc5

Getting started

Use Postal in your controller action method.

using Postal;

public class HomeController : Controller
  public ActionResult Index()
      dynamic email = new Email("Example");
      email.To = "";
      email.FunnyLink = DB.GetRandomLolcatLink();
      return View();

Create an Email, passing it the name of the view to use for the email.

Using dynamic means we can nicely assign some data to use in the view. It's also possible to create a strongly-typed email class.

Calling Send() will send the email using the .NET Framework's SmtpClient.

Postal will find the email view at Views\Emails\Example.cshtml:

To: @ViewBag.To
Subject: Important Message

You wanted important web links right?
Check out this: @ViewBag.FunnyLink


The email view specifies the headers and body content.

The ViewBag contains any data you assigned to the Email object.

Postal can work with any ASP.NET MVC view engine.


Video presentation from mvcConf 2


Postal was created by Andrew Davey. Read his blog or follow him @andrewdavey

Photo Credit: ....Tim via Compfight cc

Favicon Credit: Dakirby309 cc