Issue
- How to specify a custom email address or sender name for a workflow notification different from the default provided in portal.properties:
workflow.email.from.name=test workflow.email.from.address=test@liferay.com
Environment
- Quarterly releases
- 7.3
- 7.4
Resolution
Sender's name and email address are configured by default in the portal.properties:
workflow.email.from.name=
workflow.email.from.address=
If you wish to establish a different sender for each workflow, you can change the workflow context to provide those properties directly when executing the notification task:
workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_NAME,"newSenderName");
workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_ADDRESS,"newSenderName@newSenderName.com");
To apply this change, follow the steps outlined below, based on the "Single approver" workflow:
- Open the workflow code and navigate to the "task" element to which you have associated the notification, for example, in the example shown, it would be the "review" task.
- Add a new node of type "action" in which you include the senderName and senderAddress in the context.
- Finally, you should set the workflowContext in the serviceContext.
Here's how to apply it:
<action>
<name>review</name>
<script>
<![CDATA[
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil;
workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_NAME,"senderName");
workflowContext.put(WorkflowConstants.CONTEXT_NOTIFICATION_SENDER_ADDRESS,"sender.mail@liferay.com");
serviceContext.setAttribute("workflowContext", workflowContext);
]]>
</script>
<script-language>groovy</script-language>
<execution-type>onAssignment</execution-type>
</action>
<notification>
<name>Review Notification</name>
<template>
<![CDATA[${userName} sent you a ${entryType} for review in the workflow.]]>
</template>
<template-language>freemarker</template-language>
<notification-type>email</notification-type>
<notification-type>user-notification</notification-type>
<recipients receptionType="to">
<assignees />
</recipients>
<execution-type>onAssignment</execution-type>
</notification>
The constants workflowConstants.CONTEXT_NOTIFICATION_SENDER_NAME and workflowConstants.CONTEXT_NOTIFICATION_SENDER_EMAIL are read by the class EmailNotificationSender.java.
- If they come from the workflow context, those will always be taken.
- Otherwise, those configured in the properties we mentioned earlier are taken.