Home > Uncategorized > Send emails with out SMTP server

Send emails with out SMTP server

In this world of internet I doubt there will be an application with out the requirement of sending mails. To implement and test this common requirement developers need access to the SMTP server. Access to the SMTP server may not be possible in some secured banks. Else we will have to apply for SMTP access and this will be given for a very limited period of time. After the given period the permission to SMTP will be revoked and we will have to reapply.

This will be a problem in testing. when a developer is doing unit testing for his module that sends mails SMTP access failure may lead to a wrong conclusion else he will need to test if SMTP access is working fine. This is really a pain.

I didnt know that an elegant solution exists for this common problem. I saw this solution here.

<smtp deliveryMethod=”SpecifiedPickupDirectory”>
<specifiedPickupDirectory pickupDirectoryLocation=”c:\newemail” />

The above change in web.config will write mail to the given directory (newmail)  provided the directory has write access. Also note that this directory must exist.

C# Code:

using System.Net.Mail;

MailMessage  mail = new MailMessage();
mail.To.Add( new MailAddress(“<somemailaddress>”));
mail.From = new MailAddress(“<somemailaddress>”);
mail.Subject = “Some Subject”;
mail.Body = “Test mail body”;
SmtpClient c = new SmtpClient();
c.Host = “localhost”;

Hope this helps!

Categories: Uncategorized
  1. No comments yet.
  1. January 25, 2011 at 4:58 am

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: