Thursday, July 15, 2010

Drop emails in a folder


Instead sending an email we can configure the web.config to drop the mail in a local folder.
This is a good feature when it come to testing email on your application while developing.

Just add the following on the web.config

   1:     <system.net>
   2:       <mailSettings>
   3:         <smtp deliveryMethod="SpecifiedPickupDirectory">
   4:        <specifiedPickupDirectory pickupDirectoryLocation="C:\testmails\"/>
   5:         </smtp>            
   6:       </mailSettings>       
   7:      </system.net>


 
Following code will drop an email in your folder

   1: var smtpClient = new SmtpClient();
   2: var message = new MailMessage("from@from.com", "to@to.com");
   3: message.Subject = "This is the mail subject";            
   4: message.Body = "this is the mailm body";
   5: smtpClient.Send(message);         
 
 
Double click on the file in your C:\testmails\ folder it will open up on outlook
as an email.
 

0 comments:

My Achievements

Member of

Blog Archive

Followers

free counters