Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
Testing E-Mail Functionality

One of the most common questions I see on ASP.NET forums relates to sending E-Mail. I have addressed many of those issues already, so I wont get into how to send E-Mail from an ASP.NET web site.

This week I have been working on testing applications and had a chance to meet Donovan Brown of Notion Solutions. Donovan is all about testing and has some fantastic tools to test all aspects of applications and is a Team System freak!! This afternoon I was having a great conversation when he mentions he created a little SMTP server to test E-Mail functionality called Neptune.

All you need to do is download Neptune from Donovan’s Blog, run the installer and then run Neptune whenever you need an SMTP server to receive E-Mail sent from your application.

You can either explicitly set the SMTP server in the SMTPClient or in the web.config to ‘localhost’ or ‘127.0.0.1’ and E-Mail will be sent to Neptune. It does not really process the message, only consumes it. So it does not relay the message anywhere and you do not have to have a preset E-Mail address configured. It is really point and shoot. Each time a message is sent to Neptune it increments the Messages count. It can be reset at anytime or stopped. Stopping the SMTP server is important to make sure you application fails gracefully when it cant reach the destination SMTP server.

Neptune supports commands from RFC 821 and 2821; HELO, EHLO, MAIL, RCPT, DATA, NOOP, RSET and QUIT. It also stores the messages in memory so you can interrogate them with your testing framework, like a Visual Studio Web Test. There is also accompanying plug-in, extraction and validation rules included with Neptune.

Port 525 is used for administrative purposes. There is complete documentation included with the installation that details everything about administrating the server, testing, etc.

What Neptune isn’t or does not do, well relay E-Mail for one. It does not simulate response codes from the destination server. For example lets say the message was not delivered because the destination address does not exist or their inbox is full.

Despite those limitations I think this is a must have for software developers to have on their development machines. Even though I have my own mail server at my disposal I really like the idea of having my own little SMTP test server.

Posted: Wednesday, June 24, 2009 8:29 PM

by Chris Love
Filed under: , ,

Comments

Lee Dumond said:

Pretty neat little tool, though I'd say the inability to return status codes would definitely make it a lot nicer.
# June 24, 2009 8:55 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# June 25, 2009 5:43 AM

Sam said:

You may also like to include Papercut ( http://invalidlogic.com/papercut/ ). It's almost identical to what your describing, but its also an integrated email client. It runs on your machine, you configure your app to use it as the SMTP server (i.e. anyIP:1234), then it'll just sit there in your system tray and pop up a bubble when it recieves a message. You can then view the full source, attachments, Plain Text/Rich Text and HTML viewer to check its rendered properly. It's free.
# June 25, 2009 9:18 AM

Robert Wood said:

You might also want to check out smtp4dev (http://smtp4dev.codeplex.com) which I wrote recently. I'm currently working on a new version which allows it to be configured to return various failures.
# June 26, 2009 7:46 AM

Sanjeev Agarwal said:

Daily tech links for .net and related technologies - June 24-27, 2009 Web Development 10 Tools to Improve

# June 26, 2009 8:31 AM

MisterKen said:

http://dotnettipoftheday.org/tips/smtp-delivery-method-SpecifiedPickupDirectory.aspx How to check email works without using SMTP Testing code that sends email has always been a pain. You had to set up a SMTP service just to test that your .NET application sends the e-mail correctly. However, there is a way to send e-mails with no SMTP server set up. Just configure your .NET application to drop e-mails into a specified folder instead of sending them via SMTP server: This will instruct SmtpClient class to generate mail message, save it as .eml file and drop it into c:\Test\ folder.
# June 26, 2009 8:34 AM

Jason Young said:

I prefer Phil Haack's solution, which uses a server that you don't see, but can be queried and controlled through code. http://haacked.com/archive/2006/05/30/ATestingMailServerForUnitTestingEmailFunctionality.aspx
# June 26, 2009 3:45 PM

Chris Love said:

Jason,

Actually you can query Neptune and control it through code. There is another post coming soon.

# June 26, 2009 4:28 PM

Speednet said:

I am blown away by this topic! Thanks to Chris and all the people who commented with additional links and software. I had no idea this stuff existed, and I eagerly added everything mentioned here to my development knowledgebase. The quality of the information and software in everything mentioned here is astounding. Many thanks to the folks who wrote and published the open source projects, and for all the effort you have put into it. Chris, once again I have gotten tremendous value from your blog! Yours is on my short list for "most valuable". -Todd
# June 26, 2009 5:47 PM

Keith Elder said:

Probably an easier way to test email messages is to use the built in mechanism in .Net to send email to the file system (mostly used with things like biztalk). Just add this to your app config file and email will get written to the file system, great for unit testing, easy to test. BTW, if the directory doesnt' exist that is specified I can't remember if it gets created or throws an exception, I'm sure you'll figure it out. The best part about this is you don't need an SMTP test server and it uses the same API that you normally use. We use it alot. Enjoy.
# July 2, 2009 10:53 PM

Chris Love's Official ASP.NET Blog said:

Late last month I made a post about testing E-Mail functionality with Donovan Brown’s Neptune . Several

# July 30, 2009 10:19 PM

r4 nintendo ds said:

Are you trying to configure an SMTP server or just tryin to send mail with your own .net application? Isnt the SMTP server name required?
# September 24, 2009 7:27 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS