July 21, 2024

SamTech 365

PowerPlatform, Power Apps, Power Automate, PVA, SharePoint, C#, .Net, SQL, Azure News, Tips ….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

      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Mails\"/>


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)
          System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
           mailMessage.From = new MailAddress(From);
           mailMessage.Subject = Subject;
           mailMessage.Body = Message;
           SmtpClient smtpClient = new SmtpClient();// Rememer to change this ("smtp.your-isp.com");
           return true;
      catch (Exception ex)
           return false;