andrewdavey/postal — pull request #75 by thomasvm (2014-06-21 20:35:49+00:00)
Title: Make it easy to render preview emails

Some time ago I wanted to have an easy way to render previews of the mails in my application, a bit similar to what Rails is doing with (Action mailer previews)[http://edgeguides.rubyonrails.org/4_1_release_notes.html#action-mailer-previews].

For that reason I created a custom `ActionResult` which only takes in 1 parameter: the `Email` object that you want to preview. The idea is that you create controller methods which setup an `Email` object like you would do in other places, but instead of sending it, you pass it into the `EmailViewResult` for previewing. E.g.

public ActionResult Simple()
{
dynamic email = new Email("Simple");
email.Date = DateTime.UtcNow.ToString();

return new EmailViewResult(email);
}

Some remarks:
* the view result tries to derive the content type automatically. Text email will be rendered as text/plain, Html will have the text/html content type
* for Multipart emails you can add a query string parameter to the url to indicate which template you want to see.
* no parameter renders to main template
* ?format=text renders the text template if available
* ?format=html renders the html template
* LinkedResources that are embedded through `Html.EmbedImage()` are rendered as images with inline image data, simulating image embeds completely.
* I added a `PreviewController` class to the WebSample project to render previews of all the available templates. The samples page is extended to also include links to the preview pages (next to the send buttons)
* There are tests for all additional code.