HI, I am trying to send a simple notification using system.net.mail.mailmessage. I just pass the string as the message body. But problem is even though multi-line message be
//the email body should be HTML
//replaces the new line characters \n\r with the break HTML
mailMsg.IsBodyHtml = true;
mailMsg.Body = this.Body;
mailMsg.BodyEncoding = System.Text.Encoding.ASCII;
mailMsg.Body = mailMsg.Body.Replace(Environment.NewLine, "<br/>");
This worked for me:
mail.Body = String.Format(@"Some text here:
A new line here
And another line here");
Just be careful to not indent on the 2nd and 3rd line.
Necro ansering a question but could come in handy for some as well.
msg.IsBodyHtml = true;
AlternateView av = AlternateView.CreateAlternateViewFromString(msg.Body, new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Html));
av.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
msg.AlternateViews.Add(av);
AlternateView avPlain = AlternateView.CreateAlternateViewFromString(msg.Body, new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Plain));
avPlain.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
msg.AlternateViews.Add(avPlain);
Set the IsBodyHTML to false:
ms.IsBodyHtml = false;
By default it is false but it appears you have set it to true somewhere as outlook thinks it is HTML.