Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailMessage sent string as body without newline in outlook

Tags:

c#

mailmessage

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?

like image 739
Paul L Avatar asked Oct 14 '10 08:10

Paul L


People also ask

How do I get rid of line breaks in Outlook?

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.

Why is Outlook stripping line breaks from plain text emails?

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).

How do I insert a line break into the body of an email?

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.

How do you go to the next line in Outlook?

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!


1 Answers

//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/>"); 
like image 184
Carlos90210 Avatar answered Oct 30 '22 07:10

Carlos90210