Clone wiki

ActionMailer.Net / Home


Sorry guys, this project is no longer maintained. If you'd like to take it over, please feel free. I've posted more details on my blog.


ActionMailerNext by Crossvertise


ActionMailer.Net aims to be an easy, and relatively painless way to send email from your ASP.NET MVC application. The concept is pretty simple. We render HTML by utilizing some pretty snazzy view engines, so why can't we do the same thing for email?

This library is still in active development. I'd love to hear what you think! If you find any bugs, please don't hesitate to open an issue here on bitbucket. Pull requests and patches are always welcome, too.

Thanks JetBrains!

I just want to say thanks to JetBrains, the makers of the most awesome Visual Studio add-on, ReSharper. They have been gracious supports of ActionMailer.Net for the past year, and their tools have certainly helped me produce much higher quality code. Check them out!

Handy Screencast

I've recently recorded a screencast, so check it out on Youtube if you'd like. you can watch the video here:


Easy as pie using NuGet. Inside Visual Studio, go to View > Other Windows > Package Manager Console, and then type:

Install-Package ActionMailer


This is the easy part, I swear! There are three steps on the way to email awesomeness:

Step 1

Create a new controller in your project. I called mine MailController, but any name will do. Inside your controller, each action will need to return EmailResult objects. The best way to do that is to use the handy Email() method. Here's some sample code to get you started.

public class MailController : MailerBase
    public EmailResult VerificationEmail(User model)
        From = "";
        Subject = "Welcome to My Cool Site!";
        return Email("VerificationEmail", model);

Step 2

Now we need to create a View for this email. The view can use any ViewEngine you like, and it will even work with master pages (or layouts in Razor). The views live in the same place your normal views do.

There is one important difference between a normal ASP.NET MVC view and an ActionMailer.NET view. You need to make sure that the view's name specifies its format. Because ActionMailer.Net supports multi-part messaging, you can render views in HTML, plain text, or both.

To specify the format of your view, just append the format to the view's name. For the example email action above, if you want to send the email in plain text, your view's name should be VerificationEmail.txt. If you wish to send the email in HTML, then your view's name should be VerificationEmail.html. This means that if I'm using Razor, the full view file name should be VerificationEmail.txt.cshtml or VerificationEmail.html.cshtml.

Remember: Since ActionMailer.Net supports multi-part messaging, you can absolutely use both formats at the same time, and your message will be properly encoded.

With all that said, here's a sample plain text Razor view (with a file named VerificationEmail.txt.cshtml) that matches the nifty email action above.

@using ActionMailer.Net
@model User

    Layout = null;

Welcome to My Cool Site, @Model.FirstName

We need you to verify your email.  Click this nifty link to get verified!

@Url.AbsoluteAction("Verify", "Account", new { code = @Model.EmailActivationToken.ToString() })


Step 3

Now it's just a matter of calling your action directly any time you need to send an email. You can call it like this:

new MailController().VerificationEmail(newUser).Deliver();


There is a little bit of configuration that needs to be done, but it’s pretty easy. Under the hood, ActionMailer.Net is using System.Net.Mail.SmtpClient to send all your messages. This means that you need to add some configuration options in your project’s Web.config file. While I’m in development, I like to send all emails to a folder on my hard drive:

    <smtp deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="C:\temp\"/>

But later, when you move to production, you’ll need some more appropriate settings:

    <smtp deliveryMethod="Network">
      <network host="" userName="myuser" password="mypassword" />

Advanced Stuff

The astute reader will notice that MailerBase has a couple of virtual methods: OnMailSent and OnMailSending. Feel free to have fun with those :)

You might also notice that there is a DeliverAsync() method. I don't offer a callback here because even with Async delivery, the OnMailSent method will be called after the send operation completes.

Finally, take a look at the IMailSender interface. I provide a default implementation of this interface that uses System.Net.Mail.SmtpClient, however it should be very easy for you to implement your own version of this interface if you want to use something like Amazon SES or the SendGrid API to send stuff. Once you create your own implementation, just override the default in the constructor of your controller:

public MailController() {
    MailSender = new MyCustomMailSender();

Standalone Version

Documentation on the usage of the standalond version can be found at


The unit tests are based on TestDriven.NET. There is a Personal License available for open source developers. Once installed simply right click on the test project, or an individual test and click "Run Tests" with the TestDriven rocket icon.

Special Thanks

I'd like to thank the Rails project specifically for showing me that sending emails didn't have to suck. Without seeing ActionMailer, I would (probably) still be using StringBuilder to generate emails.

I'd also like to thank S. M. Sohan whose code I took some inspiration from (specifically the testing stuff). There were a few issues that stopped me from using his MvcMailer in my projects, but it's another good alternative for anyone that likes this system.