在Quarkus Qute模板中添加新线路

发布于 2025-02-07 18:01:46 字数 1036 浏览 0 评论 0原文

在我的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 技术交流群。

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

发布评论

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

评论(1

成熟的代价 2025-02-14 18:01:46

我相信您的问题与您的价值观有关在渲染模板时通过QUTE视为文本有关。

&lt; br&gt;如果您替换{body} {body.raw},则应工作,例如:当然

<html>
<head>
</head>

<body class="body">
<br>
    Hi <b>Receiver</b>,
    <br><br>
        {body.raw}
    <br><br>
</body>
</html>

String emailBody = "First line <br>" +
  "Second line <br>" +
  "Third line <br>" +
  "Fourth line";

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 :

<html>
<head>
</head>

<body class="body">
<br>
    Hi <b>Receiver</b>,
    <br><br>
        {body.raw}
    <br><br>
</body>
</html>

And of course :

String emailBody = "First line <br>" +
  "Second line <br>" +
  "Third line <br>" +
  "Fourth line";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文