Sending Amazon SES Emails through a Mock SMTP Server in .NET

Some have recently posted that a pitfall of the Amazon Simple Email Service is that you can't setup it up to work through a traditional SMTP as you can with other services such as SendGrid.  While Amazon SES doesn't provide a SMTP wrapper, Amazon points out that it can be used with some modifications to your existing MTA.  From the Amazon Developer Docs:

Q: Can my existing SMTP applications deliver email via Amazon SES?
Yes. The Amazon SES Developer Guide provides instructions for configuring common mail transfer agents (MTAs) to use Amazon SES as their email transport. By following these instructions, you can create a private SMTP relay for use with any existing SMTP client software.

In looking at the Amazon SES Developer Guide, they currently have examples of how to setup either Postfix or Sendmail software to use Amazon SES, and suggest adapting the examples to work with other agents.

If you want to test sending Amazon email in your own mock environment (or have an extreme situation that I don't want to know about) below is how to setup a Mock SMTP Server and use it to test sending mail via local SMTP using the Amazon SES SendRawEmail API call.

There are a number of open source Mock SMTP servers available.  For this demo I chose the Antix Mail SMTP Impostor.  It seemed to have a good bit accomplished, while not being overly complex (brief writeup here by @LeeDumond).   You can download the source code from here:

Once you've got the source code loaded up, Open FileMessageStorage.cs (in the Antix.Mail.Smtp.Impostor project).  Add a reference to the Amazon .NET SDK.

Next find the Store() function.  This function is used to store Mock emails locally on the hard drive.  Insert the following code to actually send the email out via Amazon SES.

//Send msg via Amazon SES
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient("accessKey", "secretKey");  
SendRawEmailRequest rawObj = new SendRawEmailRequest();  
rawObj.RawMessage = GetRawMessageFromString(message.Data);  
rawObj.Source = message.From.Address;  
foreach (MailAddress addressTo in message.To)  

Remember to include the namespaces

using Amazon.SimpleEmail.Model;  
using Amazon.SimpleEmail;  

That's it!  Now you can create a sample Console App or even Outlook to use your localhost to test sending emails via local SMTP.  I'm not sure if anyone would ever want to do this, but it was a fun exercise for me.