Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

How can we update the template for Mail Action in Form Container component?

Avatar

Level 1

Hello,

 

Can anyone please help me locate the template for the Mail action type in Form Container component?

 

I need to customize the template a bit by changing the wordings, etc.

 

pratikadobeaem_0-1641096512942.png

 

Currently, the default email looks like this.

pratikadobeaem_1-1641096689502.png

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @pratikadobeaem, as far as I know this is not configurable - the email structure is hardcoded and can not be changed.

By default Mail action from Form Container component is handled by com.day.cq.wcm.foundation.forms.impl.MailServlet. In other words MailServlet combines all collected data from posted form and creates email object in the structure you could observe . Once email object is created it is sent using com.day.cq.mailer.MailService implementation.

The option I can see to address your case, is to create custom servlet that will be responsible to handle Mail action - this will give you full control related to email structure. It will also allow you to use some kind of template functionality to make it more flexible.

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @pratikadobeaem, as far as I know this is not configurable - the email structure is hardcoded and can not be changed.

By default Mail action from Form Container component is handled by com.day.cq.wcm.foundation.forms.impl.MailServlet. In other words MailServlet combines all collected data from posted form and creates email object in the structure you could observe . Once email object is created it is sent using com.day.cq.mailer.MailService implementation.

The option I can see to address your case, is to create custom servlet that will be responsible to handle Mail action - this will give you full control related to email structure. It will also allow you to use some kind of template functionality to make it more flexible.

Avatar

Community Advisor

Hi,

Email is configured vai Adobe CQ Form Mail Servlet service. and there is no template is used for this. The email content is hard coded in the code.

 

e.g.

SimpleEmail simpleEmail;
        StringBuilder builder = new StringBuilder();
        builder.append(request.getScheme());
        builder.append("://");
        builder.append(request.getServerName());
        if (request.getServerPort() >= 0 && ((
          request.getScheme().equals("https") && request.getServerPort() != 443) || (request
          .getScheme().equals("http") && request.getServerPort() != 80))) {
          builder.append(':');
          builder.append(request.getServerPort());
        } 
        builder.append(request.getRequestURI());
        StringBuilder buffer = new StringBuilder();
        String text = resBundle.getString("You've received a new form based mail from {0}.");
        text = text.replace("{0}", builder.toString());
        buffer.append(text);
        buffer.append("\n\n");
        buffer.append(resBundle.getString("Values"));
        buffer.append(":\n\n");
        List<String> contentNamesList = new ArrayList<>();
        Iterator<String> names = FormsHelper.getContentRequestParameterNames(request);
        while (names.hasNext()) {
          String name = names.next();
          contentNamesList.add(name);
        } 
        Collections.sort(contentNamesList);
        List<String> namesList = new ArrayList<>();
        Iterable<Resource> formElements = this.formStructureHelperFactory.getFormStructureHelper(formResource).getFormElements(formResource);
        for (Resource field : formElements) {
          FieldDescription[] descs = FieldHelper.getFieldDescriptions(request, field);
          for (FieldDescription desc : descs) {
            contentNamesList.remove(desc.getName());
            if (!desc.isPrivate())
              namesList.add(desc.getName()); 
          } 
        } 

 

http://localhost:4502/system/console/configMgr/com.day.cq.wcm.foundation.forms.impl.MailServlet~core...



Arun Patidar