开发者

Line breaks ignored when sending mail as plain text

I have a text like " Hi, \r\n this is test \r\n Thanks" I am sending the mail using MailMessage class. I have set the "IsBodyHtml" property to false. The issue is that I am receiving mails without line breaks. Can you let me know wha开发者_JAVA百科t I am missing?


Use Environment.NewLinemsdn instead of \r\n.


We had the same problem, but if you define your message all at once in a String, as opposed to a StringBuilder, you can define your message like this:

string message = string.Format(
@"First Line: {0}
Second Line: {1}
ThirdLine: {2}", firstValue, secondValue, thirdValue);

Defining the message body like this, and setting IsBodyHtml = false, will give you the new lines that you want.

Otherwise, use StringBuilder

var sb = new StringBuilder();
sb.AppendLine("FirstLine");
sb.AppendLine("SecondLine");


This is a feature in Outlook, you can turn it off in Outlook. Go to Options - Mail - and under "Message Format" you uncheck "Remove extra line breaks in plain text messages".

Another solution is to add three spaces at the end of each line, when you send the mail. This seems to get Outlook to accept that it is not an extra line break.


If you are reading your mails from Outlook, it may be Outlook that is removing line breaks, thinking they are extra line breaks. Did you try reading your mails from another software - or maybe a webmail?


To be able to incorporate line breaks, rather than just plain test in your mail, you will need to have the body html set to true, I think.


A more tricky reason this may happen that I just had to deal with:

  • Your mail server manipulates outgoing messages and adds a html version to your otherwise text only message


I was having a similar problem where most of my line breaks were working but one was not. If I hit reply to the email that wasn't showing the line breaks, the original email text below the reply would show the line break (so this indicates it is an outlook issue). I tried the recommended answer of Environment.NewLine and that DID NOT change anything. In my case, adding a period at the end of the statement where I wanted the new line and then putting in a \r\n did the trick. Per a previous link I posted in this discussion, Outlook is using some rules to filter out line feeds and in the question that started this discussion I notice you do not have a period at the end of your sentence.


I was sending E-Mail notification via PowerShell script and also did not get any line breaks when viewing the mail in Outlook. For me the solution in the .ps1 file was this:

$emailMessage.Body = "First Line" + "`r`n" + "Second Line"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜