JBoss.orgCommunity Documentation
This chapter describes the "out-of-the-box" e. mail support available in Business Process Manager JPDL. Read this information to learn how to configure different aspects of the mail functionality.
There are four ways in which one can specify the point in time at which e. mails are to be sent from a process. Each shall be examined in turn.
Use a mail action if there is a reason not to show the e. mail as a node in the process graph.
A mail action can be added to the process anywhere that a normal action can be added.
<mail actors="#{president}" subject="readmylips" text="nomoretaxes" />
Specify the subject and text attributes as an element like this:
<mail actors="#{president}" >
<subject>readmylips</subject>
<text>nomoretaxes</text>
</mail>
Each of the fields can contain JSF-like expressions:
to='#{initiator}'
subject='websale'
text='your websale of #{quantity} #{item} was approved' />
To learn more about expressions, study Section 17.3, “ Expressions ”.
Two attribute specify the recipients: actors and to. The to attribute should "resolve" to a semi-colon separated list of e. mail addresses. The actors attribute should resolve to a semi-colon separated list of actorIds. These actorIds will, in turn, resolve to e. mail addresses. (Refer to Section 15.3.3, “ Address Resolving ” for more details.)
to='admin@mycompany.com'
subject='urgent'
text='the mailserver is down :-)' />
To learn how to specify recipients, read Section 15.3, “ Specifying Email Recipients ”
Emails can be defined by the use of templates. Overwrite template properties in this way:
<mail template='sillystatement' actors="#{president}" />
Learn more about templates by reading Section 15.4, “ Email Templates ”
As with mail actions, the action of sending an e. mail can be modeled as a node. In this case, the run-time behavior will be identical identical but the e. mail will display as a node in the process graph.
Mail nodes support exactly the same attributes and elements as the
mail action. (See Section 15.1.1, “
Mail Action
”
to find out more.)
<mail-node name="send email"
to="#{president}"
subject="readmylips"
text="nomoretaxes">
<transition to="the next node" />
</mail-node>
Always ensure that mail nodes have exactly one leaving transition.
A notification e. mail can be sent when a task is assigned to an
actor. To configure this feature, add the
notify="yes" attribute to a task in the following
manner:
<task-node name='a'>
<task name='laundry' swimlane="grandma" notify='yes' />
<transition to='b' />
</task-node>
Set notify to yes, true or
on to make the Business Process Manager send an e.
mail to the actor being assigned to the task. (Note that this e.
mail is based on a template and contains a link to the web
application's task page.)
Emails can be sent as task reminders. JPDL's reminder element utilizes the timer. The most commonly used attributes are duedate and repeat. Note that actions do not have to be specified.
<task-node name='a'>
<task name='laundry' swimlane="grandma" notify='yes'>
<reminder duedate="2 business days" repeat="2 business hours"/>
</task>
<transition to='b' />
</task-node>
The fields to, recipients,
subject and text can contain
JSF-like expressions. (For more information about expressions, see
Section 17.3, “
Expressions
”.)
One can use the following variables in expressions:
swimlanes, process
variables and transient variables
beans. Configure them via the
jbpm.cfg.xml file.
Expressions can be combined with address resolving functionality. (Refer to Section 15.3.3, “ Address Resolving ”. for more information.)
This example pre-supposes the existence of a
swimlane called president:
<mail actors="#{president}"
subject="readmylips"
text="nomoretaxes" />
The code will send an e. mail to the person that acts as the
president for that particular process execution.
Multiple recipients can be listed in the actors and to fields. Separate items in the list with either a colon or a semi-colon.
In order to send messages to a Blind Carbon Copy (BCC) recipient, use either the bccActors or the bcc attribute in the process definition.
<mail to='#{initiator}'
bcc='bcc@mycompany.com'
subject='websale'
text='your websale of #{quantity} #{item} was approved' />
An alternative approach is to always send BCC messages to some
location that has been centrally configured in
jbpm.cfg.xml. This example demonstrates how
to do so:
<jbpm-configuration>
...
<string name="jbpm.mail.bcc.address" value="bcc@mycompany.com" />
</jbpm-configuration>
Throughout the Business Process Manager, actors are referenced
by actorIds. These are strings that
serves to identify process participants. An address
resolver translates
actorIds into e. mail addresses.
Use the attribute actors to apply address resolving. Conversely, use the to attribute if adding addresses directly as it will not run apply address resolving.
Make sure the address resolver implements the following interface:
public interface AddressResolver extends Serializable {
Object resolveAddress(String actorId);
}
An address resolver will return one of the following three
types: a string, a collection of strings or an array of strings.
(Strings must always represent e. mail addresses for the given
actorId.)
Ensure that the address resolver implementation is a bean. This
bean must be configured in the jbpm.cfg.xml
file with name
jbpm.mail.address.resolver, as per this
example:
<jbpm-configuration>
<bean name='jbpm.mail.address.resolver'
class='org.jbpm.identity.mail.IdentityAddressResolver'
singleton='true' />
</jbpm-configuration>
The Business Process Manager's identity
component includes an address resolver. This address resolver
will look for the given actorId's
user. If the user exists, his or her
e. mail address will be returned. If not, null will be returned.
To learn more about the identity component, read Section 11.11, “ The Identity Component ”.
Instead of using the processdefinition.xml
file to specify e. mails, one can use a template. In this case,
each of the fields can still be overwritten by
processdefinition.xml. Specify a templates
like this:
<mail-templates>
<variable name="BaseTaskListURL"
value="http://localhost:8080/jbpm/task?id=" />
<mail-template name='task-assign'>
<actors>#{taskInstance.actorId}</actors>
<subject>Task '#{taskInstance.name}'</subject>
<text><![CDATA[Hi,
Task '#{taskInstance.name}' has been assigned to you.
Go for it: #{BaseTaskListURL}#{taskInstance.id}
Thanks.
---powered by JBoss jBPM---]]></text>
</mail-template>
<mail-template name='task-reminder'>
<actors>#{taskInstance.actorId}</actors>
<subject>Task '#{taskInstance.name}' !</subject>
<text><![CDATA[Hey,
Don't forget about #{BaseTaskListURL}#{taskInstance.id}
Get going !
---powered by JBoss jBPM---]]></text>
</mail-template>
</mail-templates>
As per the above, extra variables can be defined in the mail templates and these will be available in the expressions.
Configure the resource that contains the templates via the
jbpm.cfg.xml like this:
<jbpm-configuration>
<string name="resource.mail.templates" value="jbpm.mail.templates.xml" />
</jbpm-configuration>
Configure the mail server by setting the
jbpm.mail.smtp.host property in the
jbpm.cfg.xml file, as per this example code:
<jbpm-configuration>
<string name="jbpm.mail.smtp.host" value="localhost" />
</jbpm-configuration>
Alternatively, when more properties need to be specified, give a resource reference to a properties file in this way:
<jbpm-configuration>
<string name='resource.mail.properties' value='jbpm.mail.properties' />
</jbpm-configuration>
The following settings can be used to enable (SMTP) authentication when sending email.
Table 15.1. jBPM mail authentication properties
| Property | Type | Description |
|---|---|---|
| jbpm.mail.user | string | The email address of the user |
| jbpm.mail.password | string | The password for that email address |
| jbpm.mail.smtp.starttls | boolean | Whether or not to use the STARTTLS protocol with the SMTP server |
| jbpm.mail.smtp.auth | boolean | Whether or not to use the SMTP authentication protocol |
| jbpm.mail.debug | boolean | Whether or not to set the javax.mail.Session instance to debug mode |
The following logic is applied with regards to the above properties:
If neither the jbpm.mail.user nor the jbpm.mail.password property is set, authentication is not used regardless of other settings set.
If the jbpm.mail.user property is set, then the following is done:
The mail.smtp.submitter property is set with the value of the jbpm.mail.user property
The jbpm engine will try to login into the smtp server when sending email.
If the jbpm.mail.user property and the jbpm.mail.password property are set, then the following is done:
Everything that is done when at least the jbpm.mail.user is set, is also done in this case
The mail.smtp.auth property is set to true, regardless of the value of the jbpm.mail.smtp.auth property
The default value for the From address
field jbpm@noreply. Configure it via the
jbpm.xfg.xml file with key
jbpm.mail.from.address like this:
<jbpm-configuration>
<string name='jbpm.mail.from.address' value='jbpm@yourcompany.com' />
</jbpm-configuration>
All of the Business Process Manager's e. mail support is
centralized in one class, namely
org.jbpm.mail.Mail This class is an
ActionHandler implementation. Whenever
an e. mail is specified in the process
XML, a delegation to the mail class will
result. It is possible to inherit from the
mail class and customize certain behavior
for specific needs. To configure a class to be used for mail
delegations, specify a jbpm.mail.class.name
configuration string in the jbpm.cfg.xml
like this:
<jbpm-configuration>
<string name='jbpm.mail.class.name'
value='com.your.specific.CustomMail' />
</jbpm-configuration>
The customized mail class will be read during parsing. Actions will be configured in the process that reference the configured (or the default) mail classname. Hence, if the property is changed, all the processes that were already deployed will still refer to the old mail classname. Alter them simply by sending an update statement directed at the jBPM database.
This chapter has provided detailed information on how to configure various e. mail settings. Having studied the examples carefully, one can now practice configuring one's own environment