简体   繁体   中英

Apache Commons Mail: how get new line in simple email?

Silly newbie question. I can generate an email message body using,

email.setMsg("Paragraph 1 goes here."); 

which outputs:

Paragraph 1 goes here.

Now what I want to generate looks like:

Paragraph 1 goes here.
Paragraph 2 goes here.

But if I use:

email.setMsg("Paragraph 1 goes here."); 
email.setMsg("Paragraph 2 goes here."); 

All I get is:

Paragraph 2 goes here.

How to add manual line breaks?

Assuming you're on UNIX system:

email.setMsg("Paragraph 1 goes here.\nParagraph 2 goes here."); 

To make the code platform agnostic you can lookup the linebreak using System.getProperty("line.separator") :

String ENDL = System.getProperty("line.separator");
email.setMsg("Paragraph 1 goes here." + ENDL + "Paragraph 2 goes here."); 

If you use HTML email:

email.setMsg("<p>Paragraph 1 goes here.</p><p>Paragraph 2 goes here.</p>"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM