AEM MailService always enclose content into "pre" tag | Community
Skip to main content
homervillanueva
Level 2
October 16, 2015
Solved

AEM MailService always enclose content into "pre" tag

  • October 16, 2015
  • 6 replies
  • 1705 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sham_HC

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. 

6 replies

Sham_HC
Sham_HCAccepted solution
Level 10
October 16, 2015

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. 

homervillanueva
Level 2
October 16, 2015

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!

Level 2
October 16, 2015

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.

Adobe Employee
October 16, 2015

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

Level 2
October 16, 2015

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.

Level 2
October 16, 2015

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.