Using Amazon SES for .NET Application Mail Delivery

Published on
Reading time
Authors

Until March 2012 Amazon's Simple Email Service (SES) had limited support for mail being sent via existing .NET code and the IIS SMTP virtual server.  Some recent changes mean this is now possible so in this post I'll quickly cover how you can configure your existing apps to utilise SES.

If you don't understand why you should be using SES for your applications then you should be looking at the Amazon SES FAQ and before you start any of this configuration you need to ensure that you have created your SMTP credentials on the AWS console and that you have an appropriately validated sender address (or addresses).  Amazon is really strict here as they don't want to get blacklisted for being a spammer host.

IIS Virtual SMTP Server

Firstly, let's look at how we can setup the SMTP server as a smart host that forwards mail on to SES for you.  This approach means that you can configure all your applications to forward via IIS rather than talking directly to the SES SMTP interface.

  1. Open up the IIS 6 Manager and select the SMTP Virtual Server you want to configure.
1.iis_virtual_smtp
  1. Right-click on the server and select Properties.

  2. In the Properties Window click on the Delivery tab.

  3. On the Delivery tab click on the Outbound Security button on the bottom right.

  4. In the Outbound Security dialog select "Basic Authentication" and enter your AWS SES Credentials.  Make sure you check the "TLS Encryption" box at the bottom left of the dialog.  Click OK. Your screen should look similar to this:

2.delivery_setup
  1. Now open the Advanced Delivery dialog by clicking on the button.

  2. Modify the dialog so it looks similar to the below.  I put the internal DNS name for my host here – the problem with this is that if you shut off your Instance the name will change and you need to update this.  Click OK.

3.advanced_delivery

Now you should be ready to use this IIS SMTP Virtual Server as a relay for you applications to SES.  Make sure you set AWS SecurityGroups up correctly and that you are restricting which hosts can relay via your SMTP server.

Directly from .NET Code

Without utilising the Amazon AWS SDK for .Net you can also continue to send mail the way you always have – you will need to make the following change to your App.config or Web.config file.

<mailSettings>
    <smtp deliveryMethod="Network" from="validated@yourdomain.com">
        <network defaultCredentials="false"
                 enableSsl="true"
                 host="email-smtp.us-east-1.amazonaws.com"
                 port="25"
                 userName="xxxxxxxx"
                 password="xxxxxxxx"
        />
    </smtp>
</mailSettings>

Thanks to the author of the March 11, 2012 post on this thread on the AWS support forums for the configuration file edits above.

With these two changes most "legacy" .Net applications should be able to utilise Amazon's SES service for mail delivery.  Happy e-mailing!