Posted by: Cirilo Meggiolaro | 04/2/2009

Tip of the day #170 – Testing e-mail message formats without smtp server

Let’s imagine the following scenario: You are developing a feature that creates e-mail messages and you want to quickly test if the e-mail format is ok. To achieve that you may specify a directory where the messages will be saved so instead of trying to access the smtp server you are going to save the file that you can view in Outlook.

How to…

  • On your application’s configuration file add a smtp section and set the deliveryMethod attribute to “SpecifiedPickupDirectory”;
  • Specify a directory to save the messages by adding a specifiedPickupDirectory element and setting the pickupDirectoryLocation attribute to a path to save the messages;
  • The configuration section must be similar to the following:

        <smtp deliveryMethod=SpecifiedPickupDirectory>
            <specifiedPickupDirectory pickupDirectoryLocation=C:\MyMessages />

If you want to make a quick test, create a Message and a SmtpClient object. Both are available under the System.Net.Mail namespace. The code will be similar to the following:

MailMessage msg = new MailMessage(“”, “”);
msg.Body = “This is the message body.”;
msg.Subject = “This is the message subject.”;

SmtpClient smtp = new SmtpClient(string.Empty); //Empty just for testing purposes.

Check the directory you specified in the configuration file. An eml file with a guid name will be there. Just double-click on it to view the content on the Outlook.


  1. Never saw that before. Is that from 3.5 or we already had that in .NET 2.0?

  2. Yes. It was included in .NET 2.0.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: