Send email using ASP.Net and C#

Send email programaticaly using C# and ASP.Net. Please check sample code bellow.

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(new System.Net.Mail.MailAddress("Sample@email.com" "Receiver Name"));
mail.CC.Add(new System.Net.Mail.MailAddress("ccreceiver1@email.com" "CC Name"));
mail.From = new System.Net.Mail.MailAddress("sender@email.com", "Sender Name");
mail.Subject = "Email Subject";
mail.Body = "Email Message";
mail.IsBodyHtml = true;

System.Net.Mail.SmtpClient client = new SmtpClient();
client.Send(mail);

Use following settings in web.config file to set SMTP server, user name and password.

<system.net>
    <mailSettings>
      <smtp>
        <network host="" userName ="" password =""/>
      </smtp>
    </mailSettings>
</system.net>
Subscribe for our monthly newsletter for updated articles and useful code scripts.

Share It

comments powered by Disqus