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 read existing comments below or you can post a comment yourself on this article .

Consider making a donation
Please consider making a donation using PayPal. Your donation helps me to pay the bills so I can keep running Imar.Spaanjaars.Com, providing fresh content as often as possible.

Feedback by Other Visitors of Imar.Spaanjaars.Com

On Friday, July 3, 2009 2:11:36 PM Lee Dumond said:

There are several SMTP "development servers" that basically automate the process you just described, and provide a nice UI over it as well. Recently blogged about my favorite one:
On Friday, July 3, 2009 2:23:38 PM Imar Spaanjaars said:
Hi Lee,

Ah, many ways to Rome.... I like that.

Thanks for the update. Interesting. Just downloaded and installed it and it works great. Thanks. I wish it had two features though (can't seem to find them):

1. Configurable drop location (in case you want to keep the .eml fles)
2. Notification tips in the tray area.

Am I overlooking something? Or should I, since it's open source, create them myself? ;-)

On Wednesday, March 6, 2013 8:49:21 AM shashi said:
I need to drop mail in Project solution folder(MailDrop) or Local machine system. but not as .eml file, i want to see email content as HTML . like Example:-
once i open html file then i can see full email content

On Wednesday, March 6, 2013 2:19:31 PM Imar Spaanjaars said:
I don't think you can do that with the local drop folder. You could programmatically get the mail body from the MailMessage and store it on disk.


On Monday, November 24, 2014 9:25:46 AM Mathew said:
how can i send the mail to the end user from this directory? Do i need to write custom scripts to send it or all the Email files will be delivered automatically?
On Monday, November 24, 2014 11:59:14 AM Imar Spaanjaars said:
Hi there,

The idea here is to *not* send the e-mail so you can look at them on disk. If you want to send them to end users, either specify an SMTP server in the network element, or install a local SMTP server.



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 QuickDocId of the document.

For more information about the Talk Back feature, check out this news item.