如何使用SimpleMailMessage格式化文本?

时间:2011-03-30 08:45:55

标签: java spring email velocity

我的电子邮件内容文字是

String text = "Hey, You are create a new Account! Best, MyTeam";

如何将文字格式化为:

Hey,

You are create a new Account!

Best, MyTeam

2 个答案:

答案 0 :(得分:3)

SimpleMailMessage只能处理纯文本邮件,因此您需要在String中嵌入显式换行符:

String text = "Hey,\n\nYou are create a new Account!\n\nBest, MyTeam";

速度或自由标记等模板系统可以使这更容易。

如果您要处理HTML消息,则需要使用JavaMailSenderMimeMessagePreparator

答案 1 :(得分:0)

尝试

  

String text =“嘿,你是在创建一个新帐户!/ n Best,MyTeam”;

或者这个(如果必须在某个HTML页面内)

String text = "Hey, You are create a new Account!<br/> Best, MyTeam";

String text = "Hey, You are create a new Account! +    System.getProperty("line.separator"); + Best, MyTeam";