如何设置电子邮件中字符串的格式以便 Outlook 打印换行符?
我正在尝试用 Java 发送电子邮件,但是当我在 Outlook 中阅读电子邮件正文时,它删除了我所有的换行符。 我将 \n 放在行尾,但除此之外我还需要做一些特别的事情吗? 收件人始终使用 Outlook。
我在 microsoft.com 上发现一个页面,显示 Outlook 中有一个“删除换行符”“功能”,这是否意味着除了取消选中该设置之外没有其他解决方案可以解决该问题?
谢谢
I'm trying to send an email in Java but when I read the body of the email in Outlook, it's gotten rid of all my linebreaks. I'm putting \n at the ends of the lines but is there something special I need to do other than that? The receivers are always going to be using Outlook.
I found a page on microsoft.com that says there's a 'Remove line breaks' "feature" in Outlook so does this mean there's no solution to get around that other than un-checking that setting?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(27)
我今天刚刚为此而奋斗。 我们将删除多余换行符的行为称为“延续”。 一些实验发现以下行为:
请注意,我在 Outlook 2007 中尝试了所有这些操作。YMMV。
因此,如果可能的话,请以句子结束标点符号、制表符甚至三个空格结束所有项目符号项目。
I've just been fighting with this today. Let's call the behavior of removing the extra line breaks "continuation." A little experimenting finds the following behavior:
Please note that I tried all of this with Outlook 2007. YMMV.
So if possible, end all bullet items with a sentence-terminating punctuation mark, a tab, or even three spaces.
在换行符 (CRLF) 之前附加一个(或两个?)制表符 (\t) 时,您可以在 Outlook 中强制换行。
示例:
它似乎适用于 Outlook 2010。请测试这是否适用于其他版本。
另请参阅 Outlook 自动清理我的线路破坏并搞乱了我的电子邮件格式
You can force a line break in outlook when attaching one (or two?) tab characters (\t) just before the line break (CRLF).
Example:
It seems to work on Outlook 2010. Please test if this works on other versions.
See also Outlook autocleaning my line breaks and screwing up my email format
您需要使用
\r\n
作为解决方案。You need to use
\r\n
as a solution.默认情况下,Microsoft Outlook 2002 及更高版本会从短信中删除“额外换行符”(kb308319)。 也就是说,Outlook 似乎只是忽略文本消息中的换行符和/或回车符序列,将所有行放在一起。
如果您尝试编写自动生成电子邮件供使用 Outlook 的人阅读的代码,这可能会导致问题。
例如,为了清晰起见,假设您希望在不同的行中提供单独的信息,如下所示:
交易需要注意!
发布日期:2009 年 1 月 30 日
金额:12,222.06 美元
转运ID:8gk288g229g2kg89
邮政编码:91543
您的 Outlook 收件人将看到所有信息都被粉碎在一起,如下:
交易需要注意! 发布日期:2009 年 1 月 30 日 金额:12,222.06 美元 TransID:8gk288g229g2kg89 邮政编码:91543
似乎没有一个简单的解决方案。 替代方案是:
Microsoft Outlook 2002 and above removes "extra line breaks" from text messages by default (kb308319). That is, Outlook seems to simply ignore line feed and/or carriage return sequences in text messages, running all of the lines together.
This can cause problems if you're trying to write code that will automatically generate an email message to be read by someone using Outlook.
For example, suppose you want to supply separate pieces of information each on separate lines for clarity, like this:
Transaction needs attention!
PostedDate: 1/30/2009
Amount: $12,222.06
TransID: 8gk288g229g2kg89
PostalCode: 91543
Your Outlook recipient will see the information all smashed together, as follows:
Transaction needs attention! PostedDate: 1/30/2009 Amount: $12,222.06 TransID: 8gk288g229g2kg89 ZipCode: 91543
There doesn't seem to be an easy solution. Alternatives are:
我有同样的问题,并找到了解决方案。 试试这个:
%0D%0A
添加换行符。I had the same issue, and found a solution. Try this:
%0D%0A
to add a line break.我使用了 html 换行符而不是 "\n" 。 效果很好。
I have used html line break instead of "\n" . It worked fine.
添加“\t\r\n”(\t 代表 TAB)而不是“\r\n”在 Outlook 2010 上对我有用。 注意:在每行末尾添加 3 个空格也可以做同样的事情,但这看起来像是编程技巧!
Adding "\t\r\n" ( \t for TAB) instead of "\r\n" worked for me on Outlook 2010 . Note : adding 3 spaces at end of each line also do same thing but that looks like a programming hack!
您需要发送 HTML 电子邮件。 在电子邮件中使用
,您将始终有换行符。You need to send HTML emails. With
<br />
s in the email, you will always have your line breaks.我一直在努力解决上述所有解决方案,但这里没有任何帮助,因为我在我的电子邮件库中使用了字符串变量(来自 JTextPane 的纯文本)与“text/html”格式的组合。
因此,解决这个问题的方法是使用“text/plain”,而不是“text/html”,并且根本不需要替换返回字符:
I had been struggling with all of the above solutions and nothing helped here, because I used a String variable (plain text from a JTextPane) in combination with "text/html" formatting in my e-mail library.
So, the solution to this problem is to use "text/plain", instead of "text/html" and no need to replace return characters at all:
技巧是使用 js 中的
encodeURIComponent()
功能:结果:
The trick is to use the
encodeURIComponent()
functionality from js:RESULT:
对于 Outlook 2010 及更高版本,请使用 \t\n 而不是使用 \r\n。
For Outlook 2010 and later versions, use \t\n rather than using \r\n.
如果可以添加“.” (点)字符位于每行末尾,这似乎可以防止 Outlook 破坏文本格式。
If you can add in a '.' (dot) character at the end of each line, this seems to prevent Outlook ruining text formatting.
尝试使用
\r\c
而不是\n
。编辑:我认为@Robert Wilkinson 说得对。 <代码>\r\n。 记忆已经不再是以前的样子了。
Try
\r\c
instead of\n
.EDIT: I think @Robert Wilkinson had it right.
\r\n
. Memory just isn't what it used to be.\n
很大程度上适合我们,但 Outlook 有时确实会像您所说的那样自行删除换行符。The
\n
largely works for us, but Outlook does sometimes take it upon itself to remove the line breaks as you say.我也遇到了纯文本/文本邮件类型的问题。 早些时候,我使用了“\n\n”,但有两个换行符。 然后,我使用“\t\n”并且它起作用了。 我在 java 中使用
StringBuffer
来附加内容。内容在 Outlook 2010 邮件的下一行中打印。
I also had this issue with plain/text mail type. Earlier, I used "\n\n" but there was two line breaks. Then, I used "\t\n" and it worked. I was using
StringBuffer
in java to append content.The content got printed in next line in Outlook 2010 mail.
将文本放入
我在 HTML Body 的 CSS 内联中定义了它,如下所示:
CSS:
我定义了必须设置字体的字体系列。
HTML:
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:
i defined the font-family to have to font set.
HTML:
因为它是一个查询,所以只有百分比转义字符有效,这意味着 %0A 会给您一个换行符。 例如,
Because it is a query, only percent escaped characters work, means %0A gives you a line break. For example,
我也遇到了纯/文本邮件类型的问题。Form Feed
\f
对我有用。I also had this issue with plain/text mail type.Form Feed
\f
worked for me.有时您必须输入 \r\n 两次才能强制 Outlook 进行中断。
这将添加一个空行,但所有行都会中断。
Sometimes you have to enter \r\n twice to force outlook to do the break.
This will add one empty line but all the lines will have break.
在将正文类型设置为文本之前,\r\n 将不起作用。
\r\n will not work until you set body type as text.
我遇到了同样的问题,这是解决该问题的代码:
I was facing the same issue and here is the code that resolved it:
在我的应用程序中已解决
在我的应用程序中,我试图发送一封电子邮件,其邮件正文由用户在文本区域中键入。 发送邮件时,Outlook 自动删除用户输入的换行符。
例如,如果用户输入
亚达夫
Mahesh
Outlook 将其显示为
YadavMahesh
解决方案:我将换行符“\r\n”更改为“\par”(记住在 RTF 代码“\par”末尾按空格)并且换行符被恢复。
干杯,
马赫什
RESOLVED IN MY APPLICATION
In my application, I was trying to send an email whose message body was typed by the user in text area. When mail was send, outlook automatically removed line break entered by user.
e.g if user entered
Yadav
Mahesh
outlook displayed it as
YadavMahesh
Resolution: I changed the line break character "\r\n" with "\par " ( remember to hit space at the end of RTF code "\par" )and line breaks are restrored.
Cheers,
Mahesh
试试这个:
问候,
穆罕默德·拉苏尔·贾维德
Try this:
Regards,
Mohammad Rasool Javeed
我尝试过一个很好的解决方案,只需在行尾添加 Char(13) 即可,如下例所示:
I have a good solution that I tried it, it is just add the Char(13) at end of line like the following example:
如果消息是文本/纯文本,则 \r\n 应该可以工作;
如果消息类型是text\html,则使用
< p>>
if the message is text/plain using, \r\n should work;
if the message type is text\html, use
< p/>
如果工作需要使用没有 html 编码的格式化文本来完成。
通过以下场景可以轻松实现 动态创建 div 元素 并使用 < code>
html 元素以保持格式设置。
if work need to be done with formatted text with out html encoding.
it can be easy achieved with following scenario that creates div element on the fly and using
<pre></pre>
html element to keep formatting.不确定上面是否提到过,但 Outlook 有一个名为“删除纯文本消息中的额外换行符”的复选框设置,并且默认情况下处于选中状态。 对于不同版本的 Outlook,它位于不同的位置,但对于 2010,请转到“文件”选项卡。 选择“选项=>邮件”向下滚动到“邮件格式”取消选中该复选框。
Not sure if it was mentioned above but Outlook has a checkbox setting called "Remove extra line breaks in plain text messages" and is checked by default. It is located in a different spot for different versions of Outlook but for 2010 go to the "File" tab. Select "Options => Mail" Scroll down to "Message format" Uncheck the checkbox.