Testing SMTP in .Net

Thursday, July 23, 2009
by asalvo

I came across a blog post yesterday that showed how you can debug SMTP in .Net without having an SMTP and receiving mail server setup. As long as you are using the System.Net.Mail.SmtpClient object, you do not have to change any code at all. All you need to do is add the following to the app/web config file.

<system.net>  
  <mailSettings>  
    <smtp deliveryMethod="SpecifiedPickupDirectory">  
      <specifiedPickupDirectory pickupDirectoryLocation="C:inetpubEmailDebug"/>  
    </smtp>  
  </mailSettings>  
</system.net>

You need to make sure the the directory you specify is setup with write permissions for the account your application is running under (i.e. Network Service).

I would like to point out, that if you are following good design patterns and practices, that this would only be used for an integration test, not a unit test. In my situation, testing was not a consideration, so I’m forced to use this to “unit test”.

Comments

comments powered by Disqus