By Vaibhav Gadodia (3) on June 28th, 2009

A large number of applications today have some kind of a notification mechanism built-in. More often than not, an email is used to send these notifications. Typically, while developing these applications, developers use their own inbox to send notifications to. Or they setup some dummy account to send test emails to; or sometimes they might send test mails to real users (it’s been known to happen).

There are many limitations to this approach:

  • one has to deal with dummy messages arriving in the inbox, when all that you want to test is your email sending code.
  • automating the testing of the email sending code will result in a large number of emails being generated and delivered to your inbox.
  • code that is supposed to deliver large amounts of email will generate a lot of load on the Internet bandwidth (and yes that can be a problem).
  • if you are testing on a copy of a production database, you might inadvertently end up sending test emails to real users.

There are other issues present as well. One solution to solving these problems is to use your own SMTP server to handle all these emails in a manner that it receives an email and doesn’t sent it forward. So, it is like a dummy SMTP server. But setting up an SMTP server is usually a hassle.

There are plenty of options out there which make your job much easier than you think it is. In this post, I am going to list some solutions which can be used (though there are many more). The basic premise behind this approach is to run a local SMTP server (either on the developer box, or the test server, or both, or somewhere on the LAN). This local SMTP server address is what is configured as the server address in your application which is being tested. Any mail sent to such a server is kept with the server and not forwarded, thus preventing all the above listed issues.

Following are some of the more popular out-of-the-box programs that can be used (click on the names to go to their websites):

  • Papercut - this is a simple windows application which will run in your System Tray and simulate an SMTP server; it receives and stores any messages it receives. It allows you to view the messages. It sits in your system tray and alerts you whenever a new message arrives.
  • Neptunethis is another application which will do a similar task. It is however a little more advanced. It has an admin API interface which allows you to run custom queries to analyze the messages that it processes. It doesn’t have a UI through which you can view the received message though – but sometimes all you need to check is if the messages are being delivered. Very useful in a bulk messaging scenario.
  • smtp4dev – this is another option similar to Papercut, which again sits in the system tray and will let you know whenever any message arrives and will let you look at the message details.

There are many more out there which can be used to do similar things with some features here and there (for example, Neptune doesn’t generate all SMTP responses). Here’s a post by Phil Haack from long ago which is also interesting: A testing mail server for unit testing email functionality.

So, when you feel the need to test your email sending code the next time, it might make sense to have one of the tools (or something similar) available.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Live
  • MySpace
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • LinkedIn
  • MyShare
  • SphereIt

2 Responses to “A better way to test email sending functionality is to use your own SMTP Server”

  1. By Ryan Garaygay on Jul 31, 2009

    Another method I use from time to time (just to see if the code for sending email is ok – and even the format whatsoever) is the deliveryMethod=”SpecifiedPickupDirectory” in system.net.mailSettings

    in your web.config under the configuration element you can have

    This will place the mails (if sent successfully) in that directory and you can open it with say outlook express which comes with windows by default or inspect the actual file by other means.

    Reply

  2. By Ryan Garaygay on Jul 31, 2009

    it seems my markup didn’t make it to the comment. anyways, you can find out about it from the following link: http://msdn.microsoft.com/en-us/library/ms164241.aspx

    Reply

Post a Comment