JBoss.orgCommunity Documentation

Chapter 15.  Email Support

15.1. Mail in JPDL
15.1.1. Mail Action
15.1.2. Mail Node
15.1.3. "Task Assigned" Email
15.1.4. "Task Reminder" Email
15.2. Expressions in Mail
15.3. Specifying Email Recipients
15.3.1. Multiple Recipients
15.3.2. Sending Email to a BCC Address
15.3.3. Address Resolving
15.4. Email Templates
15.5. Mail Server Configuration
15.6. Email Authentication
15.6.1. Email authentication configuration
15.6.2. Email authentication logic
15.7. "From" Address Configuration
15.8. Customizing Email Support

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.

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" />

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:


<mail
    to='#{initiator}'
    subject='websale'
    text='your websale of #{quantity} #{item} was approved' />

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.)


<mail 
    to='admin@mycompany.com' 
    subject='urgent'
    text='the mailserver is down :-)' />

Note

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}" />

Note

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>

Important

Always ensure that mail nodes have exactly one leaving transition.

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.

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 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