Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

AEM MailService always enclose content into "pre" tag

Avatar

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

Avatar

Correct answer by
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

Avatar

Correct answer by
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. 

Avatar

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!

Avatar

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.

Avatar

Employee

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

Avatar

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.

Avatar

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.