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 been send have the correct "\r\n" format info in string. The mail opened in outlook will displayed as a long single line. But view source in outlook will display the message with correct new line format.
For example: original message would looks like:
line1
line 2
line 3
But it will displayed in Outlook like:
line1 line 2 line 3
View source from outlook will still display
line1
line 2
line 3
What should I do to make outlook display the message with correct newline information?
Open Outlook. On the File tab, select Options. In the Options dialog, select Mail. In the Message format section, clear the Remove extra line breaks in plain text messages check box.
Reason. By default, the Remove extra line breaks in plain text messages option is enabled in Outlook. So, if a line break is found, it is removed (but, if there are two or more successive line breaks, they are not removed).
Use Encoding %0D%0A in mailto body to line break. This is the only valid way to generate a line break of content/text in the body.
You can move to the next line by hitting Shift-Enter, but that is not optimal. Looking forward to a workable solution, as it is very annoying!
//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/>");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With