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
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
Have your string like below
"Your string.\n"
And:
ms.IsBodyHtml = false;
But you may get it in your Junk folder
I was able to get it to work by adding a few string spaces at the end of line prior to the troubled line.
msg.Append("\n some Message" + " ");
msg.Append("\n another message");
This worked for me
mMailMessage.IsBodyHtml = true;
Literal1.Text = "Dear Admin, <br/>You have recieved an enquiry onyour Website. Following are the details of enquiry:<br/><br/>Name: " + TextBox2.Text + "<br/>Address: " + TextBox3.Text + ", " + TextBox4.Text + "<br/>Phone: " + TextBox5.Text + "<br/>Email: " + TextBox2.Text + "<br/>Query: " + TextBox6.Text+"<br/> Regards, <br/> Veritas Team";
mMailMessage.Body = Literal1.Text;
Try using the verbatim operator "@
" before your message:
message.Body =
@"
line1
line 2
line 3
"
Consider that also the distance of the text from the left margin affects on the real sistance from the email body left margin..
Outlook will always remove line breaks, however, what can be used is the following:
In stead of using: Environment.Newline or \n\r
You should use string MyString += "this is my text" + "%0d%0A"
This %0d%0A will be recognised by outlook as the escape sequence for a new line.