Postal

Create email using ASP.NET MVC views

Install

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 = "webninja@example.com";
      email.FunnyLink = DB.GetRandomLolcatLink();
      email.Send();
      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
From: lolcats@website.com
Subject: Important Message

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

<3

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.

Documentation

Video presentation from mvcConf 2

Credits

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

Photo Credit: ....Tim via Compfight cc

Favicon Credit: Dakirby309 cc