I ran across this cool little feature of the System.Net.Mail.SmtpClient class where you can tell it that an email sent should get dumped to a directory as a .EML file instead of being sent to a SMTP server.

This is a really cool feature for DEV/QA environments where you don't always have a SMTP server that you can test against, but have code that sends email that you need to make sure its working.  I could have used this a few times where I accidentally sent out a few emails while testing that I didn't mean to.

In your Web.config file, or App.config, add the following under <configuration>

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

 

Now, when you create a MailMessage and send it through the SmtpClient, the email will be created as an .EML file in the directory you specified.

I am actually using this on my blog right now so that when people email me I don't have to have a SMTP server to have their messages sent through, I can just look at dump directory at the emails.


Posted in:   Tags:

Search Blog

Blog Roll

    OPMLDownload OPML file

    Recent Comments

    Banners

    Theme Grabber
    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010 Tony Testa's World