Test Sending Email Without an SMTP Server

By November 30, 2016.NET, ASP.NET, C#, Microsoft, Tools
SMTP4Dev Local SMTP

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):

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.

 


Also published on Medium.

The following two tabs change content below.
  • Don Starkey

    Hi Carey,

    Great Article! Do you happen to know if this works on .net core?

    Thanks

    • Carey Payette

      I can’t see why not, it’s an interceptor-type app 🙂