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("email@example.com", "firstname.lastname@example.org");
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 Carey Payette (see all)
- Pub/Sub Part 2 : REST-based Google Cloud Pub/Sub with OAuth and C# - January 27, 2017
- Pub/Sub Part 1 : C# OAuth Authentication to Google Cloud Pub/Sub using a Service Account - January 26, 2017
- Test Sending Email Without an SMTP Server - November 30, 2016
- Xamarin Quick Tip – Changing the UISegmentedControl Text Color - November 1, 2016
- Xamarin Quick Tip : Identifying if a device is an iPad or an iPhone using UserInterfaceIdiom - October 28, 2016