-1

Hi I am trying to send an email using Bold and Underline in my Message in C#

<b></b> <u></u>

How would I implement this into my code??

    var fromAddress = new MailAddress("test@gmail.com", "test");
    var toAddress = new MailAddress("test@gmail.com", "test");
    const string fromPassword = "REMOVED";
    const string subject = "Engineering Completed NewParts Project";
    const string body = "Engineering has completed their data entry on the <b><u>NewParts</b></u> project on PDMTool. / ";

    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.

user3768157
  • 41
  • 1
  • 1
  • 4

2 Answers2

0

Fix your new MailMessage declaration like so:

new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body,
    IsBodyHtml = true  // this tells the message to be sent in HTML
}
ryanulit
  • 4,983
  • 6
  • 42
  • 66
0

Set the IsBodyHtml property to true:

var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body,
    IsBodyHtml = true
}
David
  • 208,112
  • 36
  • 198
  • 279