| Jbpm Mail delivery |
| Written by Mark S. | |||||||||||||||||||||||||||||
|
Almost every workflow needs a notification of the process activity. Sending a mail from JBoss jbpm is not at all complicated. The first thing to do is telling jbpm which mail server will be used to send mail. Pickup the jbpm.cfg.xml file and add a line with the proper smtp configuration:
<jbpm-configuration> <string name="jbpm.mail.smtp.host" value="localhost" /> </jbpm-configuration> Remember that if you want jbpm to read this file - and override the basic jbpm configuration - you have to put it in the classpath : for example in a web application the simplest way is putting this file (along with processDefinition.xml) in the WEB-INF/classes folder.
1) Quick way: add Mail Action to your process definition:If for some reasons you don't want to show in your process graph the mail action <mail to=' This e-mail address is being protected from spambots. You need JavaScript enabled to view it ' subject='mail subject' text='this is the body of the mail' /> You can as well use JSF expressions <mail to='#{initiator}' subject='information' text='The following product #{product} was requested' /> In this case the value of the JSF expression is matched against ContextInstance's variables In the next tutorials we'll see how to unleash the power of jbpm with JBoss SEAM environment.
2) Show the node to the world: Use a Mail Node
<mail-node name="SendMail"
to='#{mailActor}'
subject='Ticket Opened N.# {TicketId}
Priority : #{priority}'>
<text>
<![CDATA[
Refer to: #{manager}
Text: #{textCR}
]]>
</text>
<transition to="TaskToBeDone"></transition>
</mail-node>
Again here, the value of the JSF expression is searched from the ContextInstance's variables 3) The lazy way: sending a mail automatically when a Task is assignedAnother choice is letting jbpm send a mail wherever a task is assigned. This is the typical scenario when you're designing a trouble ticket system. In this case all you have to do is adding the "notify='yes'" attribute to your task <task-node name="Assigned"> I said the lazy way, as a matter of fact it's quite simple to send mail this way..but...there's a little price to pay, that is you have to instruct jbpm to use templates.
<jbpm-configuration> <string name="jbpm.mail.smtp.host" value="mysmtp-host" /> <string name="resource.mail.templates" value="jbpm.mail.templates.xml" /> </jbpm-configuration> A mail template file is simply a file which contains templates for all kind of events, in our case we need to define a mail template for the "task-assign" event: <mail-templates> <variable name="BaseTaskListURL" value="http://localhost:8080/myapplication/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} ---powered by JBoss jBPM---]]></text> </mail-template> The JSF expressions in the template are built-in variables from your process, so you don't need to worry about adding to the Context instance anything. Yes but actorId is not an email address !
Add a last line:
<bean name='jbpm.mail.address.resolver' class='com.sample.assignment.CustomAddressResolver' singleton='true' /> Now add into your project a class which translate the actorId into the email address
public class CustomAddressResolver implements AddressResolver {
public Object resolveAddress(String actorId) {
return actorId+"@acme.com";
}
}
So actorId is injected in the method and actorId+"@acme.com" is the mail address.
JBoss.org Search
Custom Search
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
|||||||||||||||||||||||||||||




That's right: actorId is a string that jbpm usese as the identifier of the process participant.