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.
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.
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 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.
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.
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("firstname.lastname@example.org", "email@example.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!";
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.
Latest posts by Falafel Posts (see all)
- Matching Complex Query String Rewrite Rule in IIS - March 22, 2017
- Using Google Services in UWP C# Apps – Part 2 - February 7, 2017
- Using Google Services in UWP C# Apps – Part 1 - February 6, 2017
- Redis Caching in the Google Cloud Platform - February 3, 2017
- Entity Framework with Google Cloud SQL - February 2, 2017