How to formatting a text with SimpleMailMessage?

筅森魡賤 提交于 2020-05-13 04:56:59

问题


My email content text is

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

How can I format the text to:

Hey,

You are create a new Account!

Best, MyTeam

回答1:


SimpleMailMessage can only handle plain-text messages, so you need to embed explicit line-breaks in your String:

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

A templating system such as velocity or freemarker may make this easier.

If you want to handle HTML messages, you need to use JavaMailSender and MimeMessagePreparator.




回答2:


Try

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

or this(if that has to be inside some HTML page)

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

or

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


来源:https://stackoverflow.com/questions/5484036/how-to-formatting-a-text-with-simplemailmessage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!