Thursday, September 23, 2010

Create email files in .NET instead of sending emails with SpecifiedPickupDirectory

Normally in web.config we have:
<configuration>
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="Network">
                <network host="smtp.example.com" />
            </smtp>
        </mailSettings>
    </system.net>
</configuration>
Recently I learned that when developing we can output to ".eml" files directly to our C:\ drive if we configure like so:
<configuration>
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="SpecifiedPickupDirectory">
                <network host="ignored" />
                <specifiedPickupDirectory pickupDirectoryLocation="c:\ExampleEmailPickupFolder" />
            </smtp>
        </mailSettings>
    </system.net>
</configuration>
The .eml files can be opened and read using Notepad. I'm told Outlook can open them, but I'm not sure if Lotus Notes can.

If you ever want to test email capabilities while developing locally you no longer have to be shy about it, but can output directly to files. Another useful feature is that you don't have to be worry about accidently emailing a user since we know emails are not sent, but we can see what every email that would have been sent looks like.

No comments: