Wed. Nov 13th, 2019

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

Test SMTP Server for ASP.net Dev machines

Hi Guys,

If you need to test the email sending process from your asp.net application in local dev boxes (i.e. where you can’t connect to an smtp server), don’t worry, there is a fix for this.

First we need to change the web.config file

<system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Mails\"/>
      </smtp>
    </mailSettings>
  </system.net>

 

This changes implies that all emails sent are saved in C:\Mails folder, now, in order to send your email

public static bool Send(string To, string Subject, string Message, string From)
 {
      try
      {
          System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
           mailMessage.To.Add(To);
           mailMessage.From = new MailAddress(From);
           mailMessage.Subject = Subject;
           mailMessage.Body = Message;
           SmtpClient smtpClient = new SmtpClient();// Rememer to change this ("smtp.your-isp.com");
           smtpClient.Send(mailMessage);
           return true;
      }
      catch (Exception ex)
      {
           return false;
      }
 }

Leave a comment

Show Buttons
Hide Buttons
%d bloggers like this: