Wednesday, March 20, 2013

How to send an approval or rejection email in a CQ5/AEM page publishing workflow

The Problem

You want to send an email in a workflow to send an email to the author of a page, that a page has been approved or rejected.

The Solution

1. Set up email on your CQ5/AEM author instance with these instructions.
2. Create a new workflow by logging into the admin interface, and going to:

3. Click on the New button in the top left hand corner
4. Enter the title and name for your workflow. In this case:
Title: Page Approval Workflow
Name: page-approval-workflow
Click on OK.
5. Double click on the new workflow
6. You will see Step 1 as being an approval step from an administrator. You can double click on this step and change it to any group that you want to approve the article for publish. In this case, we will keep this as an admin user.
7. on the sidekick, go to Workflow, and find the OR Split process, and drag it on just after Step 1
8. on the sidekick, go to Collaboration Workflow, and find the Send Email component.
9. Drag and drop the Send Email component onto both splits of the workflow.
10. Double click on the email step on the left, and name it Approve Page, and give a description along the lines of Approve Page and sends an email to the initiator of the workflow.
11. Double click on the email step on the right, and name it Reject Page, and give a description along the lines of Reject Page with a description along the lines of Sends an email to the initiator of the workflow that the page has been rejected.
12. Click on Save
13. Open a new browser window, and go to crxde lite by navigating to:
14. Go to the following directory:
/etc/workflow and create a new folder named "demoproject"
15. create a folder inside called email
16. create a new file called emailapproval.txt
17. create a new file called emailrejection.txt
18. Click Save All
19. double click on emailapproval.txt and enter something along the following lines (Only enter the parts between, but not including the <<<<<<>>>>>>  characters

Note, instead of, enter the email address you set up as the CQ Mail Service user. I.e. This avoids any malarkey with spam filters.

<<<<<<<<<<<<Start of File>>>>>>>>>>>>>>>

From: My Name <>
To: ${}
Subject: Page Approval Granted

Hi ${},
Your page ${payload.path} has been approved and published.

Your local friendly CQ5 Admin

All Workflow properties:

<<<<<<<<<<<<End of File>>>>>>>>>>>>>>>

20. Double click on emailrejection.txt and enter the following

<<<<<<<<<<<<Start of File>>>>>>>>>>>>>>>

From: My Name <>
To: ${}
Subject: Page Rejected

Hi ${},
Your page ${payload.path} has been rejected. Please make changes and resubmit for approval.

Your local friendly CQ5 Admin

<<<<<<<<<<<<End of File>>>>>>>>>>>>>>>

21. Click on Save all, and go back to your workflow window.
22. Double click on the Approve Page step
23. go to the Arguments tab, and enter the following as the email template path:
24. click OK
25. Double click on the Reject Page step

26. go to the Arguments tab, and enter the following as the email template path:
27. click OK
28. Go to the sidekick, and select the WCM Workflow tag.
29. Add the activate page/asset step to the left hand side of the OR tag, just after the approval tag.
30. Click on Save
31. Go to the users section, and add a new user belonging to the content-authors group, with your email address specified as the user's email. You will also need to add the user to the workflow-users group.
32. In a seperate browser, log in as the newly created user.
33. Go to:
34. Click on the workflow button after highlighting the gadgets page.
35. Select page approval workflow and submit.
36. Go to the original browser, where you are logged in as admin, and navigate to:
37. Double click on the page, and you will see the page appear in edit mode.
38. Go back to the inbox page as in step 36, and click once on the workflow.
39. Click on complete.
40. Drop down the Next step combobox, and select reject.
41. Click OK.
42. The workflow should have been rejected at this point, and an email sent to the originator of the workflow process.
43. Repeat the process with your newly created user and resubmit the page. This time, as the admin user, approve the workflow.
44. You will see that the page has been published, and you should have received an email telling you that your page has been approved.


  1. Hi getign the below exception using aboave steps please let me know if u have solution for same.

    *ERROR* [pool-6-thread-25-null(null)] error while sending email for null: org.apache.commons.mail.EmailException: Sending the email to the following server failed :

  2. There seems to be a defect within cq 5.6, that when you select SSL and specify a port, the port remains on the default, which is 25.

    I'll look into a bit more and get back to you.

  3. How can you have the comments from the approval or rejection captured and put in the email?

  4. The quick and nasty way is to write the script to do so within the provided email process step by accessing the relevant node in the workflow holding the comment, however, this will be exposed to anyone with workflow edit rights.

    The more robust way is to extend the email custom workflow step, and have some settings for which workflow step to pull the approval/rejection comment from.

    Have a look at /etc/workflow/instances/2014-04-03/model_1395113338537475000/data/metaData

    Obviously the dates will differ for you, and you should be doing it relative to the workflow, but you should have the info in the /data/metadata node.

    All of these methods will leave your workflow fragile to change, as you will have an interrelation between the two workflow steps. Another alternative is to make a custom Email step that throws up a Dialog and requires the person to supply a block of text to supply to the customer. This would likely be well accepted under a lot of business cases, as the answer you have internally is likely to be worded differently than to an external party.

    Hope that helps.

  5. Nice article. It was very helpful.

  6. when we select SSL and specify a port, the port remains on the default, which is 25. is this issue fixed in AEM6 ?

  7. Is there any fix for the problem with the port number changing to 25 when enabling SSL

  8. I have created the workflow with your steps. I am facing one problem like send email step is not collaborating with reject or approval step. Send email also considered as a separate step. Is anything I need to do. Please help me to solve. Thanks