Test Sending Email Without an SMTP Server

Falafel Software Bloggers
Falafel Software
Published in
3 min readDec 1, 2016

When working on a project, I had the need to locally test the sending and formatting of an email from an application. The only downside is that I don’t have an SMTP server on my workstation, and I wasn’t about to start setting up IIS with all that ceremony. Luckily there are a couple tools that can help with this problem.

Neptune

The first tool I tried was Neptune. It doesn’t have source code available, but if you need a way to see if an email has been sent, it will show up with a notification in the system tray. You can also see a message count in the detail window. Neptune has extensions for Visual Studio that will assist with setting up unit testing, and within it the utilities obtain a string representation of the message. You can also setup unit testing through Fakes or mocks, but I digress.

Neptune Local SMTP

Neptune Local SMTP

This is a great basic tool that tests whether an email is sent from an application running on your local machine. What it does not allow you to do however, is view the message that was sent in an email client.

SMTP4Dev

SMTP4Dev is another local SMTP tool. This one has source code available on Codeplex. It doesn’t come with an installer, but the binary (exe) file is available for downloading. Simply run the executable whenever you need an SMTP server. This tool has a details Window similar to Neptune, except that it lists out the messages received. When this window is minimized it also is available in the system tray, and will display a notification when an email is received.

SMTP4Dev Local SMTP

SMTP4Dev Local SMTP

With this tool I was able to double-click the message (or select the message and tap the View button) and view the email in my associated email client, in this case Outlook. I am now able to test the formatting of my messages without depending on any external resources.

Outlook Email

Outlook Email

Here is some sample code that I used to test the functionality of these tools (add using System.Net.Mail to the top of your file):

MailMessage mail = new MailMessage("carey.payette@gmail.com", "carey@falafel.com");
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = true;
client.Host = "localhost";
mail.Subject = "This is a fantastic email subject!";
mail.Body = "This is a fantastic email body!";
client.Send(mail);

These two tools have been out for quite some time, so I am certain many of you already know about one or both. I hope this post helps someone else that may be encountering this issue for the first time.

Originally published at Falafel Software Blog.

--

--