Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to create a process step for email notification to the workflow initiator?

Avatar

Level 5

Hi,

 

There's a requirement to create content approval workflow. When the author triggeres workflow it will be notified to approver 1. When he rejects or approves the email notification has to be sent to the workflow initiator. Screenshot (31).png

 

I have attached the workflow model. 

 

Thank you

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @keerthana_hn 

 

You will have to first configure SMTP details in the Day CQ Mail Service osgi configuration. Here is an article that might help you to configure this.

Then you can use com.day.cq.mailer.MessageGateway interface in your custom process step to trigger an email. Alternatively you can use Email api from ACS commons to achieve this. Here is a link to acs commons email api.

 

Edit:
You can read workflow initiator from workflow instance. Below is the piece of code to read workflow initiator and send her the email.

            String initiator = workItem.getWorkflow().getInitiator();
            Authorizable authorizable = userManager.getAuthorizable(initiator);
            String userEmail = PropertiesUtil.toString(authorizable.getProperty("profile/email"), "");
            if(StringUtils.isBlank(userEmail)) {
                return;
            }
            HtmlEmail email = new HtmlEmail();
            email.setCharset(CharEncoding.UTF_8);
            email.addTo(userEmail);
            email.setSubject("test email subject");
            email.setMsg("text email body");
            email.setHtmlMsg("<html><head></head><body><p>html email body</p></body></html>");
            messageGateway.send(email);

 

Thanks

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @keerthana_hn 

 

You will have to first configure SMTP details in the Day CQ Mail Service osgi configuration. Here is an article that might help you to configure this.

Then you can use com.day.cq.mailer.MessageGateway interface in your custom process step to trigger an email. Alternatively you can use Email api from ACS commons to achieve this. Here is a link to acs commons email api.

 

Edit:
You can read workflow initiator from workflow instance. Below is the piece of code to read workflow initiator and send her the email.

            String initiator = workItem.getWorkflow().getInitiator();
            Authorizable authorizable = userManager.getAuthorizable(initiator);
            String userEmail = PropertiesUtil.toString(authorizable.getProperty("profile/email"), "");
            if(StringUtils.isBlank(userEmail)) {
                return;
            }
            HtmlEmail email = new HtmlEmail();
            email.setCharset(CharEncoding.UTF_8);
            email.addTo(userEmail);
            email.setSubject("test email subject");
            email.setMsg("text email body");
            email.setHtmlMsg("<html><head></head><body><p>html email body</p></body></html>");
            messageGateway.send(email);

 

Thanks

Avatar

Level 5

Hi @JeevanRaj I understood the process. but, how to initiate usermanager in workflow? using sling request? 

Avatar

Community Advisor

Below is one of the ways to get userManager.

 

UserManager userManager = AccessControlUtil.getUserManager(resourceResolver.adaptTo(Session.class));

 

Thanks