Using a Local Pickup Folder for Email Delivery

Many of the web applications I build make use of e-mail somehow. Whether it's the ASP.NET Membership services that send out account confirmations or reset passwords, or some custom logic that sends out e-mail, I typically used an SMTP server on my local network or one from an ISP. However, using a remote server isn't the fastest nor most secure way to send mail.

Storing Mail on your Local Machine

In my experience, using a real mail server during development suffers from the following problems:

  • It takes a while before the mail is delivered. It looks as if ASP.NET waits quite long before it sends out the e-mail, and then it takes some time for the mail to return in your Inbox.
  • Because of the "test" nature of the e-mails, with often just some gibberish in them, they might end up in your Spam folder so it takes a while to find them.
  • If the e-mail address you're sending the mail to exists, the mail is actually delivered. That sounds obvious, but have you ever written code like this:
  • int index = 0;
    while (index < myCustomerList.Length - 1)
      mySmtpClient.Send(me, myCustomerList[i].Email, "Hello there", mailBody);

    Ooops, forgot to update index. Now you have a very unhappy customer with a zillion e-mails in her Inbox..... ;-) (I know I can and should use foreach to prevent this problem, but the example is just meant to show the idea. Similar stuff happened in classic ASP when you looped over a RecordSet and forgot to call MoveNext, isn't that right Ane?)

  • I often see developers send mail to or Have you ever considered that these accounts could be real? What happens if there is somebody reading this account and decides to take the user name and password you sent out for a test drive? Oooops again.

Fortunately, there is a very easy way to prevent all this from happening: store the mail locally and then use a local client application to read them. Rather than having something like this in your .NET .config files:

    <smtp deliveryMethod="Network" from="">
      <network host=""/>

use something like this:

    <smtp deliveryMethod="SpecifiedPickupDirectory" from="">
      <specifiedPickupDirectory pickupDirectoryLocation="C:\TempMail"/>

From now on, your e-mail is dropped in the local folder C:\TempMail as .eml files. You can open them with Windows Mail (available on Windows Vista) or with Windows Live Mail (useful for, among other OS's, Windows 7 as it no longer ships with its own mail client). You need to create the pickup folder in advance as it's not created for you automatically.

This concept is not new at all. It just wasn't until recently that I realized how much better this option is....

Happy mailing!

Where to Next?

Wonder where to go next? You can post a comment on this article.

Doc ID 496
Full URL
Short cut
Written by Imar Spaanjaars
Date Posted 07/03/2009 13:12


Talk Back! Comment on Imar.Spaanjaars.Com

I am interested in what you have to say about this article. Feel free to post any comments, remarks or questions you may have about this article. The Talk Back feature is not meant for technical questions that are not directly related to this article. So, a post like "Hey, can you tell me how I can upload files to a MySQL database in PHP?" is likely to be removed. Also spam and unrealistic job offers will be deleted immediately.

When you post a comment, you have to provide your name and the comment. Your e-mail address is optional and you only need to provide it if you want me to contact you. It will not be displayed along with your comment. I got sick and tired of the comment spam I was receiving, so I have protected this page with a simple calculation exercise. This means that if you want to leave a comment, you'll need to complete the calculation before you hit the Post Comment button.

If you want to object to a comment made by another visitor, be sure to contact me and I'll look into it ASAP. Don't forget to mention the page link, or the Doc ID of the document.

(Plain text only; no HTML or code that looks like HTML or XML. In other words, don't use < and >. Also no links allowed.