Home JBpm Jbpm Mail delivery
11 | 03 | 2010
JBoss 5 AS Book
"JBoss AS 5 development" reviews
Please share your feedback/review with other readers!
Banner
Dashboard
Advertise with Us
Banner
RSS Feed
Login
Sign here for the NewsLetter.



Poll
What book could be in your wish list next XMas ?
 
JBoss admin resources
Banner
JBPM Books
JBoss howto

How can you solve deployment errors caused by large war/jar/ear files ?

jboss recipe of the day ...
Read More

How do you configure your .war to be deployed after your EJB ?

jboss recipe of the day ...
Read More

How do I configure a Queue/Topic to work in a cluster?

JBoss recipe of the day ...
Read More
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.


Ok. Basically there are 3 ways to send a mail from Jbpm:

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
this is your bet.This is the simplest form of mail:
 

<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.
Because of the integration between jBPM and JBoss SEAM, all of your backed beans, EJB's and other one-kind-of-stuff becomes available right inside of your process definition! For the moment : stay tuned !

 

2) Show the node to the world: Use a Mail Node


If you want that the Mail process is visible in your process graph then you can model it as a mail node. Simply drag a Mail Node from your JBPM eclipse plugin and configure the appropriate variables:
jboss jbpm
 

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

Another 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">
   <task name="TaskAssigned" notify='yes'> 
  

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.
Recall your jbpm.cfg.xml file and add a line which describe where is the email template:

 

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

That's right: actorId is a string that jbpm usese as the identifier of the process participant.
In order to translate the actor id into an email address you need an Address Resolver.






Don't be scared we're almost done: take again the jbpm.cfg.xml

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
Comments
Search
student   |2008-10-22 17:02:07
this one was really interesting.
i am working on using jBPM but we would be
using RAD 7.0 i havent tried to use the plugin in RAD thou. Do you think the
jBPM plugin for eclipse will work for RAD 7.0?
Mark   |2008-10-22 17:18:49
Hi, no I'm afraid the JBPM plugin is specifically built for Eclipse (and even
doesn't match with all release of Eclipse )
student   |2008-10-22 21:02:56
that's sad.. i just tried to install it for RAD.. it got installed but the
graphical editor doesnt show up in RAD. anyway i can fix this? this is a vary
bad news
Mark   |2008-10-23 09:25:26
I'm afraid I don't know how to hack it
If I find some news about it I'll
post it in the "recipes of the day"
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."