1

What is a good way to produce reliable integration test results for a mail service in a development environment for a .NET MVC3 web application? The email service is already isolated behind an interface and the unit tests are written for it, but I was curious if there are there any good, general tools or strategies that are available to make it easy other than spamming some email address and having some full-blown smtp server setup somewhere.

Things that should be easy to test should be:
- given a correct setup, can an email be sent
- given an incorrect setup, can we detect it and get that status back.

rgimmy
  • 293
  • 7
  • 15
  • Curious, it sounds like your trying to send out mass emails through a web page. If this is the case then you may want to read this post.http://stackoverflow.com/questions/2623872/sending-out-20-000-emails-with-asp-net – John Hartsock Feb 16 '11 at 16:19
  • Doesn't integration test imply testing it against the smtp server you'll be using? There is little value in your tests if you fake up a smtp server locally or something and test against that. – John Farrell Feb 16 '11 at 16:21
  • the value in testing it against the fake smtp server is that I can test that the service is working correctly and the emails are being sent to the smtp server correctly. I'm just making sure I can verify that everything I can possibly do is correct rather than "coding and praying" – rgimmy Feb 16 '11 at 19:10

2 Answers2

7

A good tip if you're using your web.config to store you SMTP server settings is that you can use the following configuration to dump all emails sent into a directory on your development environment.

<system.net>
  <mailSettings>
    <smtp deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="c:\email"/>
      <network host="localhost"/>
    </smtp>
  </mailSettings>
</system.net>
David Glenn
  • 24,412
  • 19
  • 74
  • 94
  • I agree with this approach. I've done something similar, implemented an EmailProviderFactory that lets you specify the default provider in the web.config. In Production it is set to give back a provider that will send emails, in Dev it is set to give back a provider that writes the emails to the file system. – rsbarro Feb 16 '11 at 18:04
0

You can use special version of SMTP servers made for testing, look at:

Testing Mail Functionality with Neptune

Antix Developer SMTP server

Dariusz
  • 15,573
  • 9
  • 52
  • 68