Search This Blog

Sunday, 24 April 2011

Testing Email Settings in Development Environment without SMTP server

When you are sending mail using SMTP Here's what the App.config settings look like :
<system.net>
<mailSettings>
<smtp>
<network host="smtp.domain.com"/>
</smtp>
</mailSettings>
</system.net>


Now just change the configuration as
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\temp\DropFolderName\"/>
</smtp>
</mailSettings>
</system.net>

What this setting will do is create the email file and drop it into the c:\temp\ DropFolderName\ folder. This setting can be used if you have your SMTP server watch a directory for new mail and it will then send it.
Now, when I send an email, like this:


public void SendMail()
{
SmtpClient smtpClient = new SmtpClient();
MailMessage mailMessage = new MailMessage("from@example.com", "to@example.com");
mailMessage.Subject = "This is the subject";
mailMessage.Body = "This is the body of message";
smtpClient.Send(mailMessage);
}

The mail message will get generated to c:\temp\DropFolderName\

2 comments:

  1. dont we need exchange server's credential for this?

    ReplyDelete
  2. No we don't need that..Email will be stored in folder..This is for testing purpose only when you don't have exchange server..While deployment you need to provide exchange server..

    ReplyDelete