Expand my Community achievements bar.

SOLVED

AEM Core Forms Container

Avatar

Level 1

When using the ootb core forms container and action type as "Mail" I am able to send the email from AEM but I would like to create my own custom email template for my use case. Can anybody point me at email template I would need to override or which template Forms Container uses to send the emails inside AEM. I know we can create our own email service and have custom template but I am more curious to know if we can override ootb email template.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

The email body is built in com.day.cq.wcm.foundation.forms.impl.MailServlet. You cannot just override the template here, you need to create your own custom servlet for the "Mail" action.

 

To create your custom servlet for mail action,

  1. Override foundation/components/form/actions/mail/forward.jsp
  2. Override this line and add a selector(XYZ)
    FormsHelper.setForwardPath(slingRequest, resource.getPath() + ".XYZ.html");
  3. Create your own MailServlet
    @Component(service = Servlet.class,
    property = {
    "sling.servlet.resourceTypes=" + "foundation/components/form/start",
    "sling.servlet.resourceTypes=" + "core/wcm/components/form/container/v2/container",
    "sling.servlet.methods=" + "POST",
    "sling.servlet.selectors=" + "XYZ",
    "service.description=" + "Form Mail Servlet"
    })
    This thread might help you. Do let me know if you have further queries.

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

The email body is built in com.day.cq.wcm.foundation.forms.impl.MailServlet. You cannot just override the template here, you need to create your own custom servlet for the "Mail" action.

 

To create your custom servlet for mail action,

  1. Override foundation/components/form/actions/mail/forward.jsp
  2. Override this line and add a selector(XYZ)
    FormsHelper.setForwardPath(slingRequest, resource.getPath() + ".XYZ.html");
  3. Create your own MailServlet
    @Component(service = Servlet.class,
    property = {
    "sling.servlet.resourceTypes=" + "foundation/components/form/start",
    "sling.servlet.resourceTypes=" + "core/wcm/components/form/container/v2/container",
    "sling.servlet.methods=" + "POST",
    "sling.servlet.selectors=" + "XYZ",
    "service.description=" + "Form Mail Servlet"
    })
    This thread might help you. Do let me know if you have further queries.