How do I format a String in an email so Outlook wi

2019-01-04 00:10发布

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

27条回答
forever°为你锁心
2楼-- · 2019-01-04 00:42

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>
查看更多
Evening l夕情丶
3楼-- · 2019-01-04 00:43

The \n largely works for us, but Outlook does sometimes take it upon itself to remove the line breaks as you say.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-04 00:44

Try this:

message.setContent(new String(body.getBytes(), "iso-8859-1"),
                    "text/html; charset=\"iso-8859-1\"");

Regards, Mohammad Rasool Javeed

查看更多
Ridiculous、
5楼-- · 2019-01-04 00:44

\r\n will not work until you set body type as text.

message.setBody(MessageBody.getMessageBodyFromText(msg));
BodyType type = BodyType.Text;
message.getBody().setBodyType(type);
查看更多
该账号已被封号
6楼-- · 2019-01-04 00:45

You need to use \r\n as a solution.

查看更多
我想做一个坏孩纸
7楼-- · 2019-01-04 00:50

This must be helpful for you. try "%0A" instead of "\n". The real source is here.

You need to add "%0A" where ever you need a new line in your code. In your case

 abcParameters.put(defConstants.REPORT_MESSAGE, "Invalid file sent by tt. Hence ffgghh  was unable
              to process it : " + s+ "%0A" +e.getMessage().toString());
查看更多
登录 后发表回答