Pass html data to Quarkus Template

67
June 28, 2022, at 05:30 AM

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.

Answer 1

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()).

Rent Charter Buses Company
READ ALSO
Can I change a keystore JKS file&#39;s alias password with only the keystore password and not the alias password?

Can I change a keystore JKS file's alias password with only the keystore password and not the alias password?

Is it possible to change a keystore alias' password without having the oldI do have the keystore's password and the alias name

116
How to deploy apache camel application on wildfly

How to deploy apache camel application on wildfly

I developed an Apache Camel application and I want to deploy it to wildflyFrom this guide https://wildfly-extras

66
How to add a unique tag to each log in logging.properties

How to add a unique tag to each log in logging.properties

My standard configuration of Tomcat 85 splits the logs into

56
How to prevent a token created with OAuth 2.0 from expiring?

How to prevent a token created with OAuth 2.0 from expiring?

I am using the google drive API and am running into a problemI have a JAVA application that follows the documentation steps to implement the service, my problem is with the token that expires every so often

65