Home > Uncategorized > How to Test Emails during the Development?

How to Test Emails during the Development?

It is very common need to test whether Emails are going to recipients or not, during our development. But your development environment may not support to send the emails.
Below are  the few such environments.
Note: Here I am considering the developing .NET application, either WinForms, or WebForms.

  1. Using Windows XP system for developement.
  2. You don’t have IIS.
  3. You have IIS, but without SMTP server configuration.
  4. In case of ASP.NET web application, you are using ASP.NET Development Server (Cassini)

In such cases, the best workaround to test emails is – Configure an 3rd party SMTP server.
Coming to the point of interest for this post…that is SMTP4Dev (http://smtp4dev.codeplex.com/). It is a dummy SMTP server, sits in the system tray and does not deliver the received messages. The received messages can be quickly viewed, saved and the source/structure inspected. Useful for testing/debugging software that generates email.

How to use it?

Step#1: Download and install it. You will find it in the system tray

And below is its interface

Step#2: Configure (Domain name, IP, Port) and start listening

Step#3: Now, your SMTP server is ready. Before testing this, add configuration setting to web.config file.
        <network host=”localhost” port=”31” defaultCredentials=”true” enableSsl=”false”  />

Step#4: Below is the code snippet to test it.

SmtpClient mailClient = new SmtpClient();
MailMessage msg = default(MailMessage);
msg = new MailMessage();
msg.From = new MailAddress(“sentFrom@EmailAddress.com”);
msg.Subject = “TEST Subject”;
msg.Body = “TEST Message”;
msg.IsBodyHtml = true;

Step#5: Once it done, you will have the mail in SMTP4Dev window, as shown below…

Step#6: In this dialog, “Inspect”, “View” are useful commands.
Inspect, will shows you the inner details of the email (like… source, headers, body… )

And you can “View” the mail in Outlook client / Windows Live mail client.

We are done with Email testing during the development it self. Very useful and hope the same for you.
Also, there is one more alternative to test emails using deliveryMethod=”SpecifiedPickupDirectory”. Refer the below links…

– Pradeep.

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: