Not a subscriber?

Join thousands of others who are building self-directed lives through creativity, grit, and digital strategy—breaking free from the 9–5.
Receive one free message a week

Sending Email in a Development Environment without an SMTP Server

Sometimes I’m not at a client location and I cannot check to make sure that an email component is working correctly. This results from not having the email server at my disposal to relay the message off of. I also run Vista, which does not come with an SMTP server.

 

Therefore my setting in the App.config wont work for development.

Here’s what the settings look like at the client location:

  <system.net>
    <mailSettings>
      <smtp>
        <network host="mail.example.com"/>
      </smtp>
    </mailSettings>
  </system.net>

 

So, while I’m developing remotely I will change the configuration to this 

  <system.net>
    <
mailSettings>
      <
smtp deliveryMethod=SpecifiedPickupDirectory>
        <
specifiedPickupDirectory pickupDirectoryLocation=c:\temp\maildrop\/>
      </
smtp>
    </
mailSettings>
  </
system.net>

 

What this setting will do is create the email file and drop it into the c:\temp\maildrop\ folder. This setting can be used if you have your SMTP server watch a directory for new mail and it will then send it, or you can use it like I am – for testing when I need to view the email without actually sending it.

Now, when I send an email, like this:

 

        [Test]
        public void SendMail()
        {
            SmtpClient smtpClient = new SmtpClient();
            MailMessage mailMessage = new MailMessage("[email protected]", "[email protected]");
            mailMessage.Subject = "This is a test";
            mailMessage.Body = "This is the body";
            smtpClient.Send(mailMessage); 
        }

 

The mail message will get generated to c:\temp\maildrop\ . Visit this location with Explorer and you’ll see something similar to this:

image

 

Now open this .eml file with any text editor (I prefer Notepad++) and you will see the contents of your email.

 

Email Contents

x-sender: [email protected]
x-receiver: [email protected]
mime-version: 1.0
from: [email protected]
to: [email protected]
date: 7 Jan 2008 18:24:10 -0700
subject: This is a test
content-type: text/plain; charset=us-ascii
content-transfer-encoding: quoted-printable

This is the body

 

Now you can test the email functionality of your application without actually having a SMTP Server.

Note: If  you’re using ASP.NET you will need to allow ASP.NET to write to the pickupDirectoryLocation.