125

我正在使用 dotnet 框架发送电子邮件。这是我用来创建消息的模板:

Date of Hire: %HireDate%
Annual Salary: %AnnualIncome%
Reason for Request: %ReasonForRequest%

Name of Voluntary Employee: %FirstName% %LastName%
Total Coverage Applied For:  %EECoverageAmount%
Guaranteed Coverage Portion: %GICoveragePortion%
Amount Subject to Medical Evident: %GIOverage%

在 Outlook 中收到邮件时,Outlook 告诉我“删除了此邮件中的额外换行符”。消息显示如下:

Date of Hire: 9/28/2001
Annual Salary: $100,000
Reason for Request: New Hire

Name of Voluntary Employee: Ronald Weasley Total Coverage Applied For:  $500,000 Guaranteed Coverage Portion: $300,000.00 Amount Subject to Medical Evident: $200,000

请注意 Outlook 如何错误地删除名称、EEOverageAmount 等后所需的换行符...

对于电子邮件收件人来说,获得格式正确的电子邮件很重要,我必须假设他们中的一些人使用 Outlook 2003。我也不能假设他们知道足以关闭自动清理功能以使邮件正确格式化。

我已经在其他邮件客户端中查看过这些消息并且它们显示正确

更多信息:

  • 我正在使用 UTF-8 BodyEncoding (msg.BodyEncoding = System.Text.Encoding.UTF8)
  • msg.Body 是从一个 UTF-8 编码的文本文件中读取的,每一行都以 crlf 结尾。

问题:如何更改消息的格式以避免此问题?

4

11 回答 11

134

You can also insert a tab character at the end of the line (just before the CR LF). This extra white space will be at the end of the line and hence not visible to user. You might prefer this to having to insert spaces on the left. Note that a single space is not enough (though perhaps multiple spaces would help, I don't know.)

于 2009-01-12T16:58:19.750 回答
101

Start every line with 2 spaces and outlook will be "tricked" into keeping your formatting.

So change

Date of Hire: %HireDate%
Annual Salary: %AnnualIncome%
Reason for Request: %ReasonForRequest%

Name of Voluntary Employee: %FirstName% %LastName%
Total Coverage Applied For:  %EECoverageAmount%
Guaranteed Coverage Portion: %GICoveragePortion%
Amount Subject to Medical Evident: %GIOverage%

to

  Date of Hire: %HireDate%
  Annual Salary: %AnnualIncome%
  Reason for Request: %ReasonForRequest%

  Name of Voluntary Employee: %FirstName% %LastName%
  Total Coverage Applied For:  %EECoverageAmount%
  Guaranteed Coverage Portion: %GICoveragePortion%
  Amount Subject to Medical Evident: %GIOverage%
^^ <--- Two extra spaces at the start of every line

Here is the article I found when researching this problem which goes into a little more depth than my answer.

于 2008-10-29T18:43:21.523 回答
26

This answer is on how to "disable" the feature from the Outlook Client.

  • Go to Tools -> "Options ..."
  • In the "Preferences" tab click on "Email Options ..."
  • Uncheck the box "Remove extra line breaks in plain text messages."
  • Hit OK

FYI:I am using Outlook 2007

于 2009-08-31T17:56:00.070 回答
6

Adding "\t\r\n" ( \t for TAB) instead of "\r\n" worked for me on Outlook 2010.

于 2016-04-12T15:05:22.983 回答
5

我总是有更好的运气将电子邮件格式化为 html。您可能仍然会遇到必须将客户端设置为允许 html 格式的最终​​用户问题,但他们通常更熟悉这一点,因为很多电子邮件确实都是 html 格式的。在添加 html 标记时,您还需要做更多的工作,但最终结果更加可控。

@ephemient also suggests: Send as both HTML and plaintext. Good clients will show the latter, Outlook will show the former, everybody is happy (except the programmer who has to do more work).

于 2008-10-29T17:32:19.577 回答
1

Expanding on the Doug L answer, since I think HTML messaging is even more ubiquitous and accepted now than in 2008 when that answer was posted. Here is a little c# snippet to help convert the body and send the message in HTML format:

body = string.Format("<font face='calibri,arial,sans-serif'>{0}<font/>", body.Replace("\r\n", "<br>"));

using (var smtpClient = new SmtpClient() { Host = smtpHost })
using (var msg = new MailMessage(from, emailDistribution, subject, body) { IsBodyHtml = true })
     smtpClient.Send(msg);
于 2017-08-17T18:02:03.057 回答
1

Auto cleaning is an outlook feature which removes extra line breaks. You can prevent it by two ways.

  • First way is to add at least 2 extra spaces before lines while sending the email through code. You can add these extra spaces only before those lines which outlook automatically removes.

  • Second way is to change outlook setting which will prevent outlook from removing extra line breaks.

enter image description here

enter image description here

于 2019-03-15T13:33:36.873 回答
0

I'm seeing the same problem when generating a plain-text email and then reading it with Outlook 2003 SP3. It appears you can avoid the removal process by it by keep the line length under 40 characters. May not always be practical.

于 2008-11-12T22:00:11.913 回答
0

Put the text in <pre> Tags and outlook will format and display the text correctly.

i defined it in CSS inline in HTML Body like:

CSS:

pre {
 font-family: Verdana, Geneva, sans-serif;
}

i defined the font-family to have to font set.

HTML:

<td width="70%"><pre>Entry Date/Time:       2013-09-19 17:06:25
Entered By:     Chris

worklog mania

____________________________________________________________________________________________________

Entry Date/Time:        2013-09-19 17:05:42
Entered By:     Chris

this is a new Worklog Entry</pre></td>
于 2013-09-24T15:43:58.570 回答
-1

My text includes '\r\n' but Outlook 2010 does not render line break. Create tokens of lines delimited by '\r\n' and envelope tokens by HTML Paragraph tags. My Email format is HTML. I am generating HTML Body for my email in the code below.

string[] tokens = Regex.Split(objTickt.Description, "\r\n");
  if (tokens.Length > 0)
  {
     foreach (string line in tokens)
     {
         //htmlTW.WriteEncodedText(objTickt.Description.Replace("\r\n", "\n\n"));
         htmlTW.RenderBeginTag(HtmlTextWriterTag.P);
         htmlTW.WriteEncodedText(line);
         htmlTW.RenderEndTag();
     }
  }
于 2014-11-13T08:53:43.273 回答
-6

将您的线路终止从 crlf 更改为 cr 或 lf。

我怀疑电子邮件的顶部仅使用 cr(或 lf),而 Outlook 希望电子邮件的其余部分遵循相同的格式。

于 2008-10-29T17:22:04.930 回答