2013-06-27 22 views
0

愚蠢的新手問題。我可以用生成電子郵件正文,Apache Commons Mail:如何在簡單的電子郵件中獲取新行?

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

,輸出:

Paragraph 1 goes here. 

現在,我要生成看起來像什麼:

Paragraph 1 goes here. 
Paragraph 2 goes here. 

但是,如果使用:

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

我得到的只是:

Paragraph 2 goes here. 

如何添加手動換行符?

回答

2

假設你是UNIX系統上:

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

爲了使代碼平臺無關,你可以使用System.getProperty("line.separator")查找斷行:

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

如果您使用HTML電子郵件:

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

完美,謝謝gerrytan! – ggkmath

相關問題