Testing Outgoing SMTP Emails - So Simple!

by Shannon Deminick 16. July 2009 06:29

At the Umbraco retreat before CodeGarden 09 in Denmark, Aaron had told me an extremely handy tip about testing outbound emails in your .Net applications. I'm not sure why I've never heard about this before and the funny thing is all of the .Net developers working in our office (including contractors) had never seen this before either! It's so incredibly simple and built into .Net, so if you don't know about this already you'll want to be using this in the future.

If you application needs to send emails for whatever reason and you’re testing locally, you generally have to make sure that you're only sending emails to your address(es) so you’re not spamming a bunch of random people. This is an easy way to get around that and lets you view all of the emails sent. Just change (in our case add) a deliveryMethod attribute to your smtp settings to SpecifiedPickupDirectory:

<system.net>
  <mailSettings>
    <smtp from="noreply@localhost" deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
    </smtp>
  </mailSettings>
</system.net>

Now, all emails that are sent, just get saved to the specified folder and you can view them with Windows Live Mail, Outlook express, Thunderbird, or whatever.

Nice!!

Tags: , ,
Categories: .Net | Umbraco

Comments

7/16/2009 11:16:25 AM #

Very nice solution.

A similar approach to this problem is to set this same setting in IIS 7.0 as serverwide setting.
That way you only have to set this setting once on your testing pc/server.

Nice!!

Ron Brouwer Netherlands

5/4/2010 4:36:03 PM #


Also you can set this while you are creating MailMessage object, this is enum for DeliveryMethod

yes but specfying it in configuration file will always good

Thank you
sandesh daddi
http://www.sanshark.com

Sandesh Daddi India

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading