Using Send Email Step of Forms Workflow using-send-email-step-of-forms-workflow

Send Email step was introduced in AEM Forms 6.4. Using this step we can build business processes or workflow which will allow you to send emails with or without attachments. The following video walks through the steps for configuring the send email component.

In this video, we take a look at configuring the Send Email component introduced in AEM Forms 6.4. To do that, we first log into AEM Forms and create a new Workflow Model. We’ll call this Workflow Model DemoSendEmailStep.
Once the Model is created, we open the Model in Edit mode.
On the left you see the various components that are available for you to be included in your Workflow. So for us we are going to filter those components by Forms Workflow and search for Send Email component. So this is a Send E-mail component, we drag and drop that component into our model. Once the component is added to a model, we need to configure that particular component. Click on Data Integration Properties to bring up the configuration sheet for the Send Email component. So the first tab is going to be the Email Details tab. There is a placeholder for holding the subject. Most of the time the subject will be a Literal value, so in our case we’ll specify this object as your request for time off. And then every email template, every sent email will be associated with an HTML email template. You can browse here and select the appropriate email template or if you know the path of the email template simply type in the path here. The email template is now associated with our Send Email component. So these values are coming from the email templates, so what these values indicate are the placeholders which have been defined in our email template. For instance, there is a placeholder called Submitter and how you populate the value of the Submitter placeholder is up to you, either it can be a Literal value or it can be retrieved from a Workflow Metadata Property. In this case we’re going to retrieve it from a Workflow Metadata Property and we’re going to specify the Metadata Property to be Retrieved or Submitter. In a similar manner, we specify a Metadata Property for the start date and End Metadata Property for the end date placeholder. What this means is there will be a Metadata Property created in our Workflow payload and that Metadata Property’s value will be used to populate the placeholder within our email template. So these Metadata Properties will be created as part of a process step before you come to this Send Email component within your workflow. Next we go to the Sender Details tab and specify Sender’s Address here. This can be a Literal value. Then we specify the recipient’s e-mail address. We pick that up from the Metadata Property.
Submitters’ email. You also have the option to specify CC or BCC recipients here. Next we go to the Attachments tab. Send Email component has the ability to specify attachments as part of an email. So the first property that we need to specify is the File Attachment Path. Most of the time, it’s going to be relative to the payload.
This means that there will be a file called DOR.pdf within my workflows payload data and we’ll use that PDF file to be sent as an attachment to this email. Once you’ve configured all your settings here, make sure you save the settings and save your Workflow Model.

As part of this article, we will walk you through the following use case:

  1. A user fills out Time Off Request Form
  2. On form submission, AEM Workflow is triggered
  3. The AEM Workflow utilizes the Send Email component to send an email with the DoR as an attachment

Before you use Send Email step make sure you configure the Day CQ Mail Service from the configMgr. Provide the values specific to your environment

Configure Day CQ Mail Service

As part of the assets associated with this article, You will get the following

  1. Adaptive Form which will trigger the workflow on submission
  2. Sample workflow that will send an email with DOR as its attachment
  3. OSGi bundle which creates the metadata properties

To get the sample running on your system, please do the following:

  1. Deploy the Developingwithserviceuser bundle

  2. Download and install setvalue bundleThis bundle contains the code for creating the metadata properties as part of the process step of the workflow.

  3. Configure Day CQ Mail Service

  4. Import and install the assets associated with this article using the package manager into CRX

  5. Launch the adaptive form. Fill in the required fields and submit.

  6. You should get an email with DocumentOfRecord as an attachment

Explore the workflow model

Take a look at the process step of the workflow. The custom code associated with the process step will create metadata property names and sets its values from the submitted data.These values are then used by the send email component.

In AEM Forms 6.5 and above you do not need this custom code to create metadata properties. Please use the variables capability in AEM Workflow

Make sure the Attachments tab of the Send Email component is configured as per the screen shot below
Send Email Attachment Tab The “DOR.pdf” value has to match the value specified in the Document of Record Path specified in the submission options of your adaptive form.