tags:

views:

44

answers:

2

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?

+1  A: 

Outlook sometimes removes newlines (it usually pops up a comment that it has done it as well), not sure exactly about the rules for when it does this but I'm fairly sure if you add a . (full stop) at the end of each line it won't remove them.

Actually, looking at this article it seems like you can also solve it by sending the emails as HTML or RTF: Line breaks are removed in posts made in plain text format in Outlook

ho1
Thank you! Works now.
pstar
But Why Why Why, outlook try to remove line break in plain text by default is beyond me!
pstar
@pstar: I think it's to counter the problems with linewrapping. As in if you send an email to me linewrapped at 80 characters and I have the same setting + that it should prefix the response with `> ` my response would wrap your lines again so your original text would end up looking quite ugly.
ho1
@ho1 thank you for explain that for me, make more sense to me.
pstar
I have no experience in terms of functionality of text editing application. But seems like to me it trying to fix the problem of handle linewrap and quote the original message by trying to remove extra newline. I think I would rather the email application try to keep my email format information as it is. Hope that they change that behaviour in Outlook 2010.
pstar
A: 

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.

Aliostad
I tried not setting or explicitly set IsBodyHtml to false, doesn't seems working either way.
pstar