Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 12. E-Mail Support
This chapter describes the "out-of-the-box" e-mail support available in the JPDL. Read this information to learn how to configure different aspects of the mail functionality.
12.1. Mail in JPDL Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
There are four ways in which one can specify the point in time at which e-mails are to be sent from a process.
12.1.1. Mail Action Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Use a mail action if there is a reason not to show the e-mail as a node in the process graph.
Note
A mail action can be added to the process anywhere that a normal action can be added.
<mail actors="#{president}" subject="readmylips" text="nomoretaxes" />
<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>
<mail actors="#{president}" >
<subject>readmylips</subject>
<text>nomoretaxes</text>
</mail>
Each of the fields can contain JSF-like expressions:
<mail to='#{initiator}' subject='websale' text='your websale of #{quantity} #{item} was approved' />
<mail
to='#{initiator}'
subject='websale'
text='your websale of #{quantity} #{item} was approved' />
Note
To learn more about expressions, see Section 14.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 12.3.3, “ Address Resolving ” for more details.)
<mail to='admin@mycompany.com' subject='urgent' text='the mailserver is down :-)' />
<mail
to='admin@mycompany.com'
subject='urgent'
text='the mailserver is down :-)' />
Note
To learn how to specify recipients, read Section 12.3, “ Specifying E-Mail Recipients ”
e-Mails can be defined by the use of templates. Overwrite template properties in this way:
<mail template='sillystatement' actors="#{president}" />
<mail template='sillystatement' actors="#{president}" />
Note
Learn more about templates by reading Section 12.4, “ E-Mail Templates ”
12.1.2. Mail Node Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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 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 12.1.1, “ Mail Action ” to find out more.)
Important
Always ensure that mail nodes have exactly one leaving transition.
12.1.3. "Task Assigned" E-Mail Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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>
<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.)
12.1.4. "Task Reminder" E-Mail Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
e-Mails can be sent as task reminders. The 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.
12.2. Expressions in Mail Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
The fields
to
, recipients
, subject
and text
can contain JSF-like expressions. (For more information about expressions, see Section 14.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 12.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" />
<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.
12.3. Specifying E-Mail Recipients Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
12.3.1. Multiple Recipients Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Multiple recipients can be listed in the actors and to fields. Separate items in the list with either a colon or a semi-colon.
12.3.2. Sending E-Mail to a BCC Address Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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' />
<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>
<jbpm-configuration>
...
<string name="jbpm.mail.bcc.address" value="bcc@mycompany.com" />
</jbpm-configuration>
12.3.3. Address Resolving Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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); }
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>
<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, their e-mail address will be returned. If not, null will be returned.
Note
To learn more about the identity component, read Section 8.11, “ The Identity Component ”.
12.4. E-Mail Templates Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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:
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>
<jbpm-configuration>
<string name="resource.mail.templates" value="jbpm.mail.templates.xml" />
</jbpm-configuration>
12.5. Mail Server Configuration Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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>
<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>
<jbpm-configuration>
<string name='resource.mail.properties' value='jbpm.mail.properties' />
</jbpm-configuration>
12.6. Email Authentication Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
12.6.1. Email authentication configuration Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
The following settings can be used to enable (SMTP) authentication when sending email.
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
|
12.6.2. Email authentication logic Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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
12.7. "From" Address Configuration Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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>
<jbpm-configuration>
<string name='jbpm.mail.from.address' value='jbpm@yourcompany.com' />
</jbpm-configuration>
12.8. Customizing E-Mail Support Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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>
<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. You can now practice configuring your own environment