SiteMap  | About    

How to send html email from C#

The System.Net classes provide the functionalities that is similar to Microsoft WinInet API . Here we are using System.Net class for sending an HTML email from the following C# program . In an HTML email , the body part contain HTML codes like HTML pages. In the previous C# program SMTP email from C# describes how to send an email with a text body . Here instead of text body part we are sending email with HTML body part.

The following C# source code shows how to send an email with HTML body part from a Gmail address . The Gmail SMTP server name is and the port using for send mail is 587 . Here using NetworkCredential for password based authentication.

using System;
using System.Windows.Forms;
using System.Net.Mail;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("");

                mail.From = new MailAddress("");
                mail.Subject = "Test Mail - 1";

                mail.IsBodyHtml = true;
                string htmlBody;

                htmlBody = "Write some HTML code here";

                mail.Body = htmlBody;

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                MessageBox.Show("mail Send");
            catch (Exception ex)

You have to provide the necessary information like your gmail username and password etc. (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.