在Quarkus Qute模板中添加新线路
在我的Quarkus项目中,我使用邮件对象在电子邮件中发送Qute模板。
在发送邮件之前,将数据从我的代码中动态添加到Qute模板中。 示例模板是
<html>
<head>
</head>
<body class="body">
<br>
Hi <b>Receiver</b>,
<br><br>
{body}
<br><br>
</body>
</html>
即使在尝试&lt; br&gt;,\ n,\\ n,system.lineseparator()
中的&lt; br&gt;,br&gt;,\ n,system.lineseparator()
的
@Inject
@Location("sampleMail")
MailTemplate mailObject;
public void sendMail() {
String emailBody = "First line <br>" +
"Second line \n" +
"Third line \\n" + System.lineSeparator() +
"Fourth line";
mailObject.to(recipient)
.subject("Default subject")
.data("body", emailBody)
.send().subscribe().with(
success -> logger.info("Message sent"),
fail -> logger.error("Exception while sending mail", fail));
}
}
示例模板也不会呈现新行在邮件中发送的HTML中的QUTE模板中。所有行都存在于一行中,未创建新行。已经检查了Quarkus指南,但没有提及。
是否有解决此问题的解决方案或建议?
In my Quarkus project, I am sending an qute template in an email using mail object.
The data is dynamically added to qute template from my code before sending the mail.
The sample template is
<html>
<head>
</head>
<body class="body">
<br>
Hi <b>Receiver</b>,
<br><br>
{body}
<br><br>
</body>
</html>
The email body is added from code using this
@Inject
@Location("sampleMail")
MailTemplate mailObject;
public void sendMail() {
String emailBody = "First line <br>" +
"Second line \n" +
"Third line \\n" + System.lineSeparator() +
"Fourth line";
mailObject.to(recipient)
.subject("Default subject")
.data("body", emailBody)
.send().subscribe().with(
success -> logger.info("Message sent"),
fail -> logger.error("Exception while sending mail", fail));
}
}
Even after trying <br>, \n, \\n, System.lineSeparator()
in body string, the new line is not rendered in qute template in the html that is being sent in the mail. All lines are present in one single line, new line is not created. Have checked the quarkus guides but there was no mention about this.
Any solution or suggestions for solving this issue ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您的问题与您的价值观有关在渲染模板时通过QUTE视为文本有关。
&lt; br&gt;
如果您替换{body}
{body.raw}
,则应工作,例如:当然:
I believe your problem is related to your values being treated as text by Qute when rendering your template.
The
<br>
should work if you replace your{body}
by{body.raw}
, like this :And of course :