Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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 4

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.  

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

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.