Skip to main content
Mar 30, 2023 8:50 PM UTC
Solved

AEM Core Forms Container

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
JeevanRaj
JeevanRajAccepted solution
Community Advisor
Mar 31, 2023 4:37 PM UTC

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.

3 replies

JeevanRaj
Community Advisor
JeevanRajCommunity AdvisorAccepted solution
Community Advisor
Mar 31, 2023 4:37 PM UTC

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.
Translate
May 6, 2024 9:47 AM UTC

Is it still working for AEMaaCS? With overlayed forward.jsp I can see 302 redirect in browser but without selector defined so my servlet is not triggering.

Translate
JeevanRaj
Community Advisor
Community Advisor
May 6, 2024 10:06 AM UTC

I haven't tried this in AEMaaCS. Works with AEM 6.5.

Translate