Free programming examples and instructions

Send email with HTML template - C#

code for how to send email with html template in Asp.net - c#

by Athil

Posted on 27 Aug 2017 Category: Asp.net Views: 340

Edited on 27 Aug 2017

Hi, Here I am going to show how to send an email with HTML template.

Use the name space

using System.Net.Mail;
 protected void Button1_Click(object sender, EventArgs e)
                string from = "[email protected]";
                string namefrom = "stranger from";
                MailMessage mail = new MailMessage();
                string smtpClientID = "mail.something.com";
                int portno = 587;

                SmtpClient SmtpServer = new SmtpClient(smtpClientID);

                mail.From = new MailAddress(from, namefrom);

                List<string> to = new List<string>();
                to.Add("[email protected]");
                to.Add("[email protected]");
                // Add emails for reciepts
                string subject = "Demo for send email with html template";
                foreach (string mailto in to)
                string message = "<html>Your html code</html>"; // Add the complete html code here 
                //Use scripts and jss as per the tempplate
                string password = "your password";
                mail.Subject = subject;
                mail.Body = message;
                mail.IsBodyHtml = true; //make it true to send with html templete
                SmtpServer.Port = portno;
                SmtpServer.Credentials = new System.Net.NetworkCredential(from, password);
            catch (Exception E) {


Leave a Comment: