1

I was wondering how to allow my message body to use HTML? I don't get an error it just sends as text when I receive emails while using this code.

Here is my code:

    var fromAddress = new MailAddress("example@gmail.com", "Bivar PDMTool");
    var toAddress = new MailAddress("example@bivar.com", "PDMTool");
    const string fromPassword = "REMOVED";
    const string subject = "Plant Completed PM3-PM5-PR Project";
    const string body = "Plant has completed their data entry on the <span style='text-decoration: font-family: arial, helvetica, sans-serif;'><em>PM3-PM5-PR</em></span> project on PDMTool.<br><br> http://pdmtool.bivar.com/ ";

    var smtp = new SmtpClient
               {
                   Host = "smtp.gmail.com",
                   Port = 587,
                   EnableSsl = true,
                   DeliveryMethod = SmtpDeliveryMethod.Network,
                   UseDefaultCredentials = false,
                   Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
               };
    using (var message = new MailMessage(fromAddress, toAddress)
                         {
                             Subject = subject,
                             Body = body
                         })
    {
        smtp.Send(message);
    }
}

Thank you

  • `{Subject=subject, Body=body, IsBodyHtml = true}` – EZI Jul 22 '14 at 18:44
  • 1
    possible duplicate of [How to send HTML-Formated email?](http://stackoverflow.com/questions/8628683/how-to-send-html-formated-email) – Nicolas Jul 22 '14 at 18:45

1 Answers1

1

Change

 using (var message = new MailMessage(fromAddress, toAddress)
                         {
                             Subject = subject,
                             Body = body
                         })
    {
        smtp.Send(message);
    }

to

using (var message = new MailMessage(fromAddress, toAddress)
                         {
                             Subject = subject,
                             Body = body,
                             IsBodyHtml = true;
                         })
    {
        smtp.Send(message);
    }
RandomUs1r
  • 4,010
  • 1
  • 24
  • 44