Using a Local Pickup Folder for Email Delivery
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 blah@test.com or somebody@nobody.com. 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:
<system.net> <mailSettings> <smtp deliveryMethod="Network" from="You@yourprovider.com"> <network host="smtp.yourprovider.com"/> </smtp> </mailSettings> </system.net>
use something like this:
<system.net> <mailSettings> <smtp deliveryMethod="SpecifiedPickupDirectory" from="You@yourprovider.com"> <specifiedPickupDirectory pickupDirectoryLocation="C:\TempMail"/> </smtp> </mailSettings> </system.net>
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.
Links in this Document
Doc ID | 496 |
Full URL | https://imar.spaanjaars.com/496/using-a-local-pickup-folder-for-email-delivery |
Short cut | https://imar.spaanjaars.com/496/ |
Written by | Imar Spaanjaars |
Date Posted | 07/03/2009 13:12 |
Comments
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.