ScioSoft's Community Blogs Optimized IT musings for the technically inclined

Test sending email on Localhost in ASP.NET: The SMTP server alternative

by James Fielding 4. March 2010 09:43

Out of the box, Visual Studio is a wonderful environment for creating and testing ASP.NET applications. This includes Microsoft's free Express Edition, which is, as some of you know, a great place to start building sites. One thing that can be challenge to test are a site's email related subroutines. A standard and effective approach is to configure the SMTP server on your test machine. Unfortunately, if you send a project to somebody that doesn't have the identical SMTP test environment set up (which is pretty much never), you're going to have problems.

If you only need to test that your project can create an email, an alternative is to use the Specified Pickup Directory method, which simply has your test environment save the email, instead of actually sending it. To accomplish this, you need to add or replace the default mail settings in your project's web.config file:


<configuration>
    ....
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="SpecifiedPickupDirectory">
                <specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
            </smtp>
        </mailSettings>
    </system.net>
    ....
</configuration>

As you can probably guess, you can change the pickup directory for your email to anything you want, but take note: The directory has to exist, otherwise you'll get an error. This is particularly important if you are sending your project to somebody else, and don't want them to be stuck debugging your application. So, the temp folder is actually a decent place to store and access test emails.

The great thing about using the Specified Pickup Directory method is that you can use your production email settings throughout the project, and simply swap out the web.config mailSettings when your done testing. You can also send your email enabled projects to somebody else and have it work as expected.

Specified Pickup Directory is not a silver bullet, because sometimes you actually do want to do a test send, as opposed to just saving the email. However for most situations, particularly preliminary testing, this method will probably fit your needs.

Happy emailing,
James Fielding

kick it on DotNetKicks.com
Shout it

Sciosoft Systems is a Canadian web design & development company based in Muskoka, which is in central Ontario. We provide ASP.NET website & Windows Server application development services to small and medium-sized business, as well as local government and not-for-profit groups. If you have a website project you’d like to discuss, please visit us at www.sciosoft.com.

Share |

Tags: , , , , , , ,

Web Development | ASP.NET

RecentComments

Comment RSS

The opinions expressed herein are the personal opinions of the contributors and do not necessarily represent the views of Sciosoft Systems Inc.