MailMessage 将字符串作为正文发送,在 Outlook 中不带换行符
您好,我正在尝试使用 system.net.mail.mailmessage 发送简单的通知。我只是将字符串作为消息正文传递。但问题是,即使发送的多行消息在字符串中具有正确的“\r\n”格式信息。邮件 在 Outlook 中打开将显示为长单行。但在 Outlook 中查看源代码将以正确的换行格式显示消息。
例如: 原始消息看起来像:
line1
line 2
line 3
但它将在 Outlook 中显示为:
line1 line 2 line 3
从 Outlook 查看源代码仍将显示
line1
line 2
line 3
我应该怎样做才能使 Outlook 显示带有正确换行信息的消息?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
Outlook 有时会删除换行符(它通常会弹出一条评论,表明它也这样做了),不确定何时执行此操作的具体规则,但我相当确定您是否添加了
.
(句号)在每行的末尾,它不会删除它们。实际上,看看这篇文章,您似乎还可以通过以 HTML 或 RTF 格式发送电子邮件来解决它: 换行符在 Outlook 中以纯文本格式发布的帖子中被删除
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
And:
But you may get it in your Junk folder
这对我有用
This worked for me
//电子邮件正文应该是HTML
//用换行符替换换行符 \n\r HTML
//the email body should be HTML
//replaces the new line characters \n\r with the break HTML
Outlook 总是会删除换行符,但是,可以使用以下内容:
而不是使用:
环境.换行符
或者
\n\r
你应该使用
string MyString += "this is my text" + "%0d%0A"
这个 %0d%0A 将被 Outlook 识别为新行的转义序列。
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.
将 IsBodyHTML 设置为 false:
ms.IsBodyHtml = false;
默认情况下,它是 false,但似乎您已在某处将其设置为 true,因为 Outlook 认为它是 HTML。
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.
这对我有用:
只要小心不要在第二行和第三行缩进。
This worked for me:
Just be careful to not indent on the 2nd and 3rd line.
我可以通过在有问题的行之前的行尾添加一些字符串空格来使其工作。
I was able to get it to work by adding a few string spaces at the end of line prior to the troubled line.
死灵回答了一个问题,但对某些人来说也可能派上用场。
Necro ansering a question but could come in handy for some as well.
尝试在邮件前使用逐字运算符“
@
”:考虑到文本距左边距的距离也会影响距电子邮件正文左边距的实际距离。
Try using the verbatim operator "
@
" before your message:Consider that also the distance of the text from the left margin affects on the real sistance from the email body left margin..