Expand my Community achievements bar.

Introducing Adobe LLM Optimizer: Own your brand’s presence in AI-Powered search and discovery
SOLVED

AEM Forms: how to send email as HTML content type?

Avatar

Level 3

I have a form with the submit action set to "Send email" and the email template path set to a .txt file under /libs/fd/dashboard/templates/email. The email is always sent with the content type text/plain instead of text/html. For the contents of the template, I have tried multiple things: copying that of htmlEmailTemplate.txt, editing that to include only a simple test <div>, replacing everything with a full HTML page (starting with DOCTYPE), etcetera. I'm using AEM 6.5.13.

1 Accepted Solution

Avatar

Correct answer by
Level 3

I ended up creating a workflow to send the email, and put the template under /apps/mysite instead of under /libs. For the form's submit action, select "Invoke an AEM workflow".

 

For the workflow:

- Add a variable "dataxml" of type XML, plus String variables for placeholders in the template.

- Add the Set Variables step. Map dataxml using the "Relative to payload" method to value "Data.xml", plus any other variables (I used the "Literal" method for all of the others).

- Add the Send Email step (from Forms workflows). Under Email Details, set the path to the template, then map the template placeholders to the variables.

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @wizard04wsu,

 

Adobe CQ Form Mail Servlet handles the Mail Action type of Form Container (see implementation in the com.day.cq.wcm.foundation.forms.impl.MailServlet). 

 

Based on its implementation, it can send 2 types of emails:

  1. Multi-part email when attachments more than 1: org.apache.commons.mail.MultiPartEmail
  2. Simple email: org.apache.commons.mail.SimpleEmail

 

To send an HTML email, you need to use org.apache.commons.mail.HtmlEmail. 

 

There is a good AEM Email API provided by ACS Commons: https://adobe-consulting-services.github.io/acs-aem-commons/features/e-mail/email-api/index.html. It allows you to use different email templates persisted in the repository, to send attachments etc.

 

I see 2 options for you:

  1. create project-specific form action implementation (foundation/components/form/action). There are examples: /libs/foundation/components/form/actions/mail, /apps/core/wcm/components/form/actions/rpc. You will need to register a new servlet where you will use ACS Commons Email service, 
  2. override the default Mail servlet by registering a custom MailServlet with the same declaration as com.day.cq.wcm.foundation.forms.impl.MailServlet but with a higher service ranking. In it, you can use ACS Commons Email Service.

I would suggest implementing option 1 because it won't affect OOTB code and will work separately.  

Kostiantyn Diachenko



Check out AEM VLT Intellij plugin


I will give that a try! Thank you for the guidance.

Avatar

Employee

Will you able to achieve this? I want to beatify the url in email template and to achieve this I overlayed in conf and added a div but then it is giving null null in email

Avatar

Correct answer by
Level 3

I ended up creating a workflow to send the email, and put the template under /apps/mysite instead of under /libs. For the form's submit action, select "Invoke an AEM workflow".

 

For the workflow:

- Add a variable "dataxml" of type XML, plus String variables for placeholders in the template.

- Add the Set Variables step. Map dataxml using the "Relative to payload" method to value "Data.xml", plus any other variables (I used the "Literal" method for all of the others).

- Add the Send Email step (from Forms workflows). Under Email Details, set the path to the template, then map the template placeholders to the variables.

Avatar

Moderator

@wizard04wsu , We have introduced a new feature that enables Adaptive Form authors to easily use HTML email templates. This feature allows you to send rich, personalized emails—including form data—upon form submission. Reach out to us at aem-forms-ea@adobe.com if you  want to use this capability, so we can enable it for your environments. Thanks!

 

html-email.png