jBPM decision nodes development jBPM task nodes development
Feb 15

jBPM mail node

jBPM mail nodes are simple nodes designed only to send mails. This time you don’t have to implement any handler or function, jBPM libraries provide nearly all you need.

In mail info tab you can set the destination e-mail address, the subject and the mail body that is going to send. This will be useful when you know destination e-mail address, orders@mycompany.com, for instance.

If you need to send mails to workflow actors, you can set a user variable in context:

executionContext.setVariable("user", workflowActor);

and configure mail info as it follows:

jBPM mail info

jBPM address resolver will check for user e-mail address from database and send him the mail, you will have to do nothing!

This is a great node but I had some requirements that it didn’t provide to me, so I re-implemented it, adding some new methods.

You can download new implementation here.

Now I can send mails using a gmail account. To explain it in a simple way, my implementation read some extra parameters from jbpm.cfg.xml file before sending the mail.

  <string name="jbpm.mail.smtp.host" value="smtp.gmail.com" />
  <bean   name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />
  <string name="jbpm.mail.from.address" value="yourMail@gmail.com" />
  <string name="jbpm.mail.user" value="yourUser@gmail.com" />
  <string name="jbpm.mail.pass" value="yourPassword" />
  <string name="jbpm.mail.port" value="465" />
  <string name="jbpm.mail.smtp.socketFactory.port" value="465" />
  <string name="jbpm.mail.smtp.socketFactory.class" value="javax.net.ssl.SSLSocketFactory" />
  <string name="jbpm.mail.smtp.auth" value="true" />
  <string name="jbpm.mail.smtp.starttls.enable" value="true" />
  <string name="jbpm.mail.debug" value="true" />
  <string name="jbpm.mail.smtp.socketFactory.fallback" value="false" />
  <string name="jbpm.mail.advanced.config" value="true" />
  <string name='mail.class.name' value='FastSign.mail.Mail' />

If jbpm.mail.advanced.config is set to false it works as the original mail node. Setting it to true, activates the extra parameters. In this case, 465 is gmail port, I suppose you can change it to use other system. Note that you have to define mail.class.name with the correct package.

I hope this will be useful.

Related Posts

24 Responses to “jBPM mail nodes development”

  1. Marques Says:

    Hi,

    you are doing here a nice work! Thanks!

    One question, we can put some variable in the context like you have made:
    executionContext.setVariable(”user”, workflowActor);
    But do you know how to delete one?
    Thanks
    Marques

  2. Marques Says:

    so i’ve found…
    it’s executionContext.getProcessInstance().getContextInstance().deleteVariable(”STRING”);

    if someone need it like me ^-^

  3. Marques Says:

    hi,

    so now I’ve the problem that he doesn’t accept
    executionContext.setVariable(”Variable”, myVariable);

    do you have an idea?

    thanks

  4. Marques Says:

    hi,

    so now I’ve the problem that he doesn’t accept
    executionContext.setVariable(”Variable”, myVariable);

    he makes an exception in hibernateException:
    instance not of expected entity type: org.jbpm.conext.exe.variableInstance
    do you have an idea?

    i tried to convert myVariable to the type object but the errer persists…

    thanks

  5. pigui Says:

    What kind of type are you using? You can’t no use simple types like int. String, Integer, etc are working correctly in my projects

  6. Marques Says:

    hi,

    i’m using a type that i’ve defined.
    example:
    MyVar MVar = new MyVar(executionContext);
    executionContext.setVariable(”MVar”,MVar);

    but it seems to work.
    I’ve tried also with String, int and with this types I had no problem.

    After this I tried with executionContext.setVariable(”MVar”,MVar.toString());
    and it works…but I have other problems…
    and I don’t know if I can receive my variable back…

  7. pigui Says:

    Does your class implements Seriarizable? You must implement it if you want hibernate save/reconstruct your objects.

  8. Marques Says:

    no she was not seriarizable…that was the fault…
    thanks ;)

  9. Fornachari Says:

    Hi pigui, nice job, thanks to post informations to help other people.

    Please, could you give a little help, somethings are not very clear to me.

    When I create a new jBpm project, the jbpm.cfg.xml file is created automatically in the root of the claspath and it came empty, so uses the file org/jbpm/default.jbpm.cfg.xml to get the informations needed, right?

    When I fill the jbpm.cfg.xml file with the informations that you wrote above (jbpm.mail.smtp.host, jbpm.mail.port, …) will my process automatically get the informations from the jbpm.cfg.xml file and not more from org/jbpm/default.jbpm.cfg.xml?

    My jBPM version is 3.2.2.

    Thank you

    Regards

  10. pigui Says:

    @Fornachari
    Hi Fornachari.
    I’m always creating my complete config file and placing it inside my project.
    You can load it using this function:

    static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource( “ProjectName/config/jbpm.cfg.xml”);

    I hope it helps you.

  11. Ramesh Says:

    Having problem between these lines

    String mailTemplatesResource = JbpmConfiguration.Configs.getString(”resource.mail.templates”);
    org.w3c.dom.Element mailTemplatesElement = XmlUtil.parseXmlResource(mailTemplatesResource, true);

    I am using JBPM 3.3.0 GA, can u modify it..

    signature is: public static Document parseXmlResource(String resource, boolean isJbpmConfiguration) {

  12. NautilusVN Says:

    Hi,

    Thank for you post.

    I have a problem. The system announced to me that he couldn’t resolve class FastSign.mail.Mail.

    Can you tell me that class is your own or it come from some jar library? and please tell me its function?

    Thank so much!

  13. pigui Says:

    Hi NautilusVN

    I developed this class some time ago and it worked fine. Where did you place it? You will have to adapt the package to your path or place it inside a FastSign/mail folder.

  14. shankar Says:

    Can you keep entire project zip/war file on the site, to download?
    Or can you plz email it to me?

    Thanks
    Shankar

  15. pigui Says:

    @shankar
    Which project?

  16. shankar Says:

    Hi pigui, I was asking about a sample project which uses mail node.

    Problem, I am facing is as below:

    I have configured value for property “jbpm.mail.port” in jbpm.cfg.xml file.

    But this port is not getting used while sending email.
    I am getting below error:

    Caused by: javax.mail.SendFailedException: Sending failed;
    nested exception is:
    class javax.mail.MessagingException: Could not connect to SMTP host: MUM-EXCH01.shritech.corp, port: 25, response: -1
    at javax.mail.Transport.send0(Transport.java:218)
    at javax.mail.Transport.send(Transport.java:80)

  17. pigui Says:

    I’m sorry I can not share the code of that project.

  18. shankar Says:

    At least, let me know:
    Why the port 25 is getting used instead of the port I configured?

  19. pigui Says:

    Did you set

    jbpm.mail.advanced.config" = "true"

    ?

  20. shankar Says:

    resolved the problem.
    The problem was with mail.class.name configuration.
    Thank u.

  21. pigui Says:

    @shankar

    Perfect :)

  22. Anand Says:

    static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseResource( “ProjectName/config/jbpm.cfg.xml”);

    How to set the JBPMConfiguration in the jbpm4.0 as there is no method called parseResource() in it.

    Please help me in mail.properties configuration in jbpm 4.0

  23. Anand Says:

    i am getting the following errors:

    [DefaultCommandService] exception while executing command org.jbpm.pvm.internal.cmd.StartProcessInstanceInLatestCmd@1deba30
    java.lang.NullPointerException
    at org.jbpm.pvm.internal.email.impl.MailSessionImpl.send(MailSessionImpl.java:47)
    at org.jbpm.jpdl.internal.activity.MailActivity.perform(MailActivity.java:44)
    at org.jbpm.jpdl.internal.activity.JpdlAutomaticActivity.execute(JpdlAutomaticActivity.java:15)
    at org.jbpm.pvm.internal.model.op.ExecuteActivity.perform(ExecuteActivity.java:60)
    ……….
    ……
    ………
    ………

  24. pigui Says:

    @Anand

    I’m not working with jBPM 4.0 so I can’t help you. I’m sorry.

Leave a Reply