Sending email in ASP.NET using SMTP configuration from web.config

Posted by Pardhu2020 under ASP.NET category on | Points: 40 | Views : 4388
In this code snippet, we are going to use following namespace

using System.Net.Mail;
Here is a simple snippet of how to send an email message from “” to multiple email recipients (note that the To a CC properties are collections and so can handle multiple address targets).

In the web.config file, please write below configuration.

<smtp from="">
<network host="" port="587" userName="" password="xxxxx"/>

In the ASP.NET code behind page, you will need to write following code in a method that will be called to send email.

SmtpClient cle = new SmtpClient();
MailMessage mailMsg = new MailMessage();
mailMsg.Subject = "task 3";
mailMsg.IsBodyHtml = true;
mailMsg.Body += "This is an automated notification of transaction details from Bergen County Golf System." + "<br />";
mailMsg.Body += "<br />";
mailMsg.Body += "-----------------------------------------------------" + "<br/>";
mailMsg.Body += "Order Summary" + "<br/>" + "<br/>";

In the above code snippet, we have instantiated SmtpClient object that exists into the System.Net.Mail namespace. After that we have also instantiated MailMessage object.

Comments or Responses

Login to post response