How can we update the template for Mail Action in Form Container component? | Adobe Higher Education
Skip to main content
January 2, 2022
解決済み

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

  • January 2, 2022
  • 2 の返信
  • 1254 ビュー

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.

 

 

Currently, the default email looks like this.

 

このトピックへの返信は締め切られました。
ベストアンサー lukasz-m

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.

2 の返信

lukasz-m
Community Advisor
lukasz-mCommunity Advisor回答
Community Advisor
January 2, 2022

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.

arunpatidar
Community Advisor
Community Advisor
January 2, 2022

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-components

Arun Patidar
June 22, 2022

So we cannot modify the underlying logic?