How to send HTML-Formated email?

Best way to send html formatted Email

This code will be in “Customer.htm

      Dealer's Company Name

Read HTML file Using System.IO.File.ReadAllText. get all HTML code in string variable.

string Body = System.IO.File.ReadAllText(Server.MapPath("EmailTemplates/Customer.htm"));

Replace Particular string to your custom value.

Body = Body.Replace("#DealerCompanyName#", _lstGetDealerRoleAndContactInfoByCompanyIDResult[0].CompanyName);

call SendEmail(string Body) Function and do procedure to send email.

public static void SendEmail(string Body)
    MailMessage message = new MailMessage();
    message.From = new MailAddress(Session["Email"].Tostring());
    message.Subject = "Request from " + SessionFactory.CurrentCompany.CompanyName + " to add a new supplier";
    message.IsBodyHtml = true;
    message.Body = Body;

    SmtpClient smtpClient = new SmtpClient();
    smtpClient.UseDefaultCredentials = true;

    smtpClient.Host = ConfigurationSettings.AppSettings["SMTP"].ToString();
    smtpClient.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["PORT"].ToString());
    smtpClient.EnableSsl = true;
    smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["USERNAME"].ToString(), ConfigurationSettings.AppSettings["PASSWORD"].ToString());

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s