Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM MailService always enclose content into "pre" tag

homervillanueva
Level 2
Level 2

Hi All,

I am using com.day.cq.mailer.MailService to send email and noticed that whenever I use HTML template it always enclose the template content "pre" tag. My concern is that since it enclose the HTML content into "pre" tag, all my CSS styling is does not reflect because of this. Is there any solution to change this behavior?

My template contains

From: ${fromEmail} Subject: ${subject} <div> <br/> Hi ${toName},<br/> <br/> Your account has been created. To activate your account, please click the following link:<br/><br/> <a href="${link}" >${link}</a><br/><br> Thank You,<br/> ${fromName}<br/> </div>

And the resulting email when it sent

 

<html><body><pre><div> <br/> Hi homervillanueva,<br/> <br/> Your account has been created. To activate your account, please click the following link:<br/><br/> <a href="http://localhost/register/activate.html?token=24912749237492374" >http://localhost/register/activate.html?token=24912749237492374</a><br/><br> Thank You,<br/> Operation Team<br/> </div></pre></body></html>

 

Appreciate for any input and advice.

Thanks!

1 Accepted Solution
Sham_HC
Correct answer by
Level 10
Level 10

OOB HtmlEMailTemplate just replace the variables and does not append any elements.  Seems like issue at other layer. Verify in the node where template is stored <pre> element exists? If so then look at component may be rte or some custom transformer  adding it. 

View solution in original post

6 Replies
Sham_HC
Correct answer by
Level 10
Level 10

OOB HtmlEMailTemplate just replace the variables and does not append any elements.  Seems like issue at other layer. Verify in the node where template is stored <pre> element exists? If so then look at component may be rte or some custom transformer  adding it. 

View solution in original post

homervillanueva
Level 2
Level 2

Hi Sham HC,

The HTML content which I posted above is the actual content of the HTML template i created, nothing more - nothing less.  But when the email is sent the whole content of the template is enclosed inside pre, body and html tag. I have no idea where these added tags came from as they were not existing in my template.

 

Thanks!

alvin_l
Level 2
Level 2

Hi,

Is this solved? I am having the same issue right now but I couldn't find the solution or any possible place inserting the <pre> tag.

Thanks.

kalyanar
Employee
Employee

can you paste the code snippet with which you send mail?

alvin_l
Level 2
Level 2

Hi kalyanar,

Please see below:

 

ArrayList<InternetAddress> emailRecipients = new ArrayList<InternetAddress>(); emailRecipients.add(new InternetAddress(email_address)); Map<String, String> mailTokens = new HashMap<String, String>(); mailTokens.put("xxx", xxx); mailTokens.put("yyy", yyy); HtmlEmail email = new HtmlEmail(); Resource templateRsrc = request.getResourceResolver().getResource(templatePath); final MailTemplate mailTemplate = MailTemplate.create(templateRsrc.getPath(), templateRsrc.getResourceResolver().adaptTo(Session.class)); email = mailTemplate.getEmail(StrLookup.mapLookup(mailTokens), HtmlEmail.class); email.setCharset("UTF-8"); email.setTo(emailRecipients); if (messageGatewayService != null) { messageGateway = messageGatewayService.getGateway(HtmlEmail.class); messageGateway.send(email); }

 

templatePath link to a html node eg. "/workflow/email/xxx.html", thanks for your reply.

alvin_l
Level 2
Level 2

Hi,

Just in case if anyone need solution, this issue is temporary fixed by wrapping my HTML email content with a "<pre style="white-space:initial"> HTML CONTENT </pre>".

Thanks.