如何使用 SimpleMailMessage 设置文本格式?

发布于 2024-10-28 04:17:08 字数 192 浏览 1 评论 0原文

我的电子邮件内容文本是

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

如何将文本格式设置为:

Hey,

You are create a new Account!

Best, MyTeam

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-11-04 04:17:08

SimpleMailMessage 只能处理纯文本消息,因此您需要在字符串中嵌入显式换行符:

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

诸如velocity 或freemarker 之类的模板系统可能会使这变得更容易。

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

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.

感性不性感 2024-11-04 04:17:08

尝试

String text = "Hey, You are create a new Account!/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") + "Regards, MyTeam";

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") + "Regards, MyTeam";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文