I am using Quarkus Mailer and Quarkus Template to create an endpoint that will be responsible just for sending emails. For now it just receives the subject, body and the emails that the email should be sent to. I am using Quarkus Template so that I have a base html template for all emails. However I want to be able to pass html through the endpoint so that I am able to render different styles in the content of the template.
This is the part of the template where the body is rendered:
<tr style='mso-yfti-irow:5;height:343.95pt'>
<td width=621 valign=top style='width:466.05pt;border-top:none;border-left: solid #0E133C 2.25pt;border-bottom:none;border-right:solid #0E133C 2.25pt; padding:2.0cm 1.0cm 1.0cm 1.0cm;height:343.95pt'>
<p class=MsoNormal><span lang=PT style='mso-ansi-language:PT'>{sendEmailRequest.getBody()}<o:p></o:p></span></p>
</td>
</tr>
Basically the "sendEmailRequest.getBody()" has the html content and it is currently being rendered like this:
This is the code used to send the email:
public void sendEmail(final SendEmailRequest sendEmailRequest) {
final String html = template.data("sendEmailRequest", sendEmailRequest).render();
mailer.send((new Mail()).setSubject(sendEmailRequest.getSubject())
.setHtml(html)
.setTo(sendEmailRequest.getTos()));
}
Keep in mind that I want to keep using a base template for the email and not directly use the body received from the DTO as the whole email body. I already managed to use html from the endpoint, but that was wihtout using the template.
CodePudding user response:
I posted the same question as an issue in the Quarkus repository and the solution was provided.
You can check it ou here: https://github.com/quarkusio/quarkus/issues/23893
The solution:
You need to output the unescaped value: (1) either use the raw or safe computed properties in the template ({content.raw} or {content.safe}) or (2) wrap the String value in a io.quarkus.qute.RawString (template.data("content", new RawString(content)).render()).