-
1. Re: How to use Email service in JBPM 5.x?
rajvij Jun 28, 2012 12:14 PM (in response to rajvij)It is simple all you need to have a valid SMTP available.
Rest add following code to your process java file.
startUp();
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);
EmailWorkItemHandler emailHandler1 = new EmailWorkItemHandler();
emailHandler1.setConnection("smtp.gmail.com","587", "uremailId", "password");
emailHandler1.getConnection().setStartTls(true);
ksession.getWorkItemManager().registerWorkItemHandler("Email",emailHandler1);
ksession.startProcess("com.sample.bpmn.hello");
System.out.println("Process started ...");
-
2. Re: How to use Email service in JBPM 5.x?
valle Aug 23, 2012 10:23 AM (in response to rajvij)hello,
i have a runable process and want to send an email from a task befor the process ends. I built the process in the designer 2.2.
Is it possible to use the code snippets in the designer? Maybe in an OnExitAction?
If not, what exactly (step by step) do i have to do to use these code in eclipse?
-
3. Re: How to use Email service in JBPM 5.x?
rajvij Aug 23, 2012 11:44 AM (in response to valle)Okay, trying a simple process to send an email might help you.
Create a process having only a start node, an email component and at the end.... The end node. Now copy the code that is mentioned above, provide your Gmail is and the password.
On running the process an email to your account should be sent.
Let me know if you are facing any other issues.
Cheers
R D Vij
-
4. Re: How to use Email service in JBPM 5.x?
valle Aug 24, 2012 2:35 PM (in response to rajvij)thx for the quick response. I created a really simple process just using a start event, mail task and end event like you told me, but when I execute it an exception is thrown. I changed the ProcessMain.java into the following code.
public class ProcessMain {
public static final void main(String[] args) throws Exception {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// email
EmailWorkItemHandler emailHandler = new EmailWorkItemHandler();
emailHandler.setConnection("smtp.gmail.com", "465", "myusername@gmail.com", "mypassword");
emailHandler.getConnection();
ksession.getWorkItemManager().registerWorkItemHandler("Email", emailHandler);
// start a new process instance
ksession.startProcess("com.sample.bpmn.hello");
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
}
and this is the exception message:
Exception in thread "main" org.jbpm.workflow.instance.WorkflowRuntimeException: [com.sample.bpmn.hello:1 - Email:4] -- Unable to send email
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:130)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerNodeInstance(NodeInstanceImpl.java:205)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:164)
at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:124)
at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)
at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:303)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:168)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:138)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:130)
at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1077)
at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:315)
at com.sample.ProcessMain.main(ProcessMain.java:29)
Caused by: java.lang.RuntimeException: Unable to send email
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:65)
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:37)
at org.jbpm.process.workitem.email.EmailWorkItemHandler.executeWorkItem(EmailWorkItemHandler.java:68)
at org.drools.process.instance.impl.DefaultWorkItemManager.internalExecuteWorkItem(DefaultWorkItemManager.java:70)
at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:105)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:124)
... 14 more
Caused by: java.lang.RuntimeException: Connection failure
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:59)
... 19 more
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1922)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:56)
... 19 more
-
5. Re: How to use Email service in JBPM 5.x?
salaboy21 Aug 24, 2012 2:37 PM (in response to valle)Hi, the exception is clear
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
You are not even connecting to the mail server. I'm not sure if it's a good idea to use a public email server to do that.. probably they don't allow you to do that or you will need to set up all the authentications mechanisms required by google.
If you have an internal mail server that will work, but your problem now is the connection with the mail server.
Cheers
-
6. Re: How to use Email service in JBPM 5.x?
salaboy21 Aug 24, 2012 2:38 PM (in response to salaboy21)I recommend you to create a simple test case which test how to send emails, and then you can include that into your processes.
Cheers
-
7. Re: How to use Email service in JBPM 5.x?
rajvij Aug 24, 2012 11:32 PM (in response to valle)I think you are using the wrong port #, try what Maurricio has suggested. Once you've a simple java application sending mail, there isn't anything more that should block you.
Cheers
R D Vij
-
8. Re: How to use Email service in JBPM 5.x?
valle Aug 25, 2012 9:40 AM (in response to rajvij)it's working! I've got a simple mail application running now and like you said, there shouldn't anything more block me from integrating this in more sophisticated workflows. thanks everybody
in case someone is facing a similar problem, this is the code snippet I used (in ProcessMain.java):
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
EmailWorkItemHandler emailHandler = new EmailWorkItemHandler();
emailHandler.setConnection("smtp.gmail.com", "587", "<username>@gmail.com", "<password>");
emailHandler.getConnection().setStartTls(true);
ksession.getWorkItemManager().registerWorkItemHandler("Email", emailHandler);
// start a new process instance
ksession.startProcess("com.sample.bpmn.hello");
-
9. Re: How to use Email service in JBPM 5.x?
rehankhan Jan 16, 2013 8:17 AM (in response to rajvij)i got error ,
come
org.jbpm.workflow.instance.WorkflowRuntimeException: [com.sample.bpmn:1 - Email:2] -- Unable to send email
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:132)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerNodeInstance(NodeInstanceImpl.java:279)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:238)
at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:126)
at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:194)
at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:309)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:170)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:140)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:132)
at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1093)
at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:315)
at ProcessMain.main(ProcessMain.java:38)
Caused by: java.lang.RuntimeException: Unable to send email
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:65)
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:37)
at org.jbpm.process.workitem.email.EmailWorkItemHandler.executeWorkItem(EmailWorkItemHandler.java:68)
at org.drools.process.instance.impl.DefaultWorkItemManager.internalExecuteWorkItem(DefaultWorkItemManager.java:70)
at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:107)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:126)
... 14 more
Caused by: java.lang.RuntimeException: Connection failure
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:59)
... 19 more
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. o5sm12992941pay.5
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:57)
... 19 more
-
10. Re: How to use Email service in JBPM 5.x?
shahdhaval2020 Feb 4, 2013 8:33 AM (in response to valle)Hey i used the same code as u had written but i am getting this error what does this mean????
i have used email service task in process design .....i.e., start node -> email service task -> end node..
can u plz help me out
=============================== MyProcessmain.java=======================================
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.process.workitem.email.EmailWorkItemHandler;
/**
* This is a sample file to launch a process.
*/
public class ProcessMain {
public static final void main(String[] args) throws Exception {
// // load up the knowledge base
// KnowledgeBase kbase = readKnowledgeBase();
// StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// // start a new process instance
// ksession.startProcess("com.sample.bpmn.hello");
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
EmailWorkItemHandler emailHandler = new EmailWorkItemHandler();
emailHandler.setConnection("smtp.gmail.com", "587", "shahdhaval2020@gmail.com", "fool123456");
emailHandler.getConnection().setStartTls(true);
ksession.getWorkItemManager().registerWorkItemHandler("Email", emailHandler);
// start a new process instance
ksession.startProcess("com.sample.bpmn.hello");
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
// load up the knowledge base
}
=========================sample.bpmn=============================================
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
targetNamespace="http://www.jboss.org/drools"
typeLanguage="http://www.java.com/javaTypes"
expressionLanguage="http://www.mvel.org/2.0"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
xmlns:g="http://www.jboss.org/drools/flow/gpd"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:tns="http://www.jboss.org/drools">
<process processType="Private" isExecutable="true" id="com.sample.bpmn.hello" name="Hello World" >
<!-- nodes -->
<startEvent id="_1" name="StartProcess" />
<endEvent id="_3" name="EndProcess" >
<terminateEventDefinition/>
</endEvent>
<task id="_4" name="Email" tns:taskName="Email" >
<ioSpecification>
<inputSet>
</inputSet>
<outputSet>
</outputSet>
</ioSpecification>
</task>
<!-- connections -->
<sequenceFlow id="_4-_3" sourceRef="_4" targetRef="_3" />
<sequenceFlow id="_1-_4" sourceRef="_1" targetRef="_4" />
</process>
<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="com.sample.bpmn.hello" >
<bpmndi:BPMNShape bpmnElement="_1" >
<dc:Bounds x="16" y="16" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" >
<dc:Bounds x="345" y="38" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_4" >
<dc:Bounds x="115" y="37" width="100" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_4-_3" >
<di:waypoint x="165" y="61" />
<di:waypoint x="369" y="62" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_1-_4" >
<di:waypoint x="40" y="40" />
<di:waypoint x="165" y="61" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
==============================================
And when i run this i am getting following output on console
=====>>>>
OUTPUT
==================
Exception in thread "main" org.jbpm.workflow.instance.WorkflowRuntimeException: [com.sample.bpmn.hello:1 - Email:4] -- Email must have one or more to adresses
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:130)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerNodeInstance(NodeInstanceImpl.java:205)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:164)
at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:124)
at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)
at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:303)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:168)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:138)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:130)
at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1077)
at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:315)
at com.sample.ProcessMain.main(ProcessMain.java:33)
Caused by: java.lang.RuntimeException: Email must have one or more to adresses
at org.jbpm.process.workitem.email.EmailWorkItemHandler.createEmail(EmailWorkItemHandler.java:86)
at org.jbpm.process.workitem.email.EmailWorkItemHandler.executeWorkItem(EmailWorkItemHandler.java:67)
at org.drools.process.instance.impl.DefaultWorkItemManager.internalExecuteWorkItem(DefaultWorkItemManager.java:70)
at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:105)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:124)
... 14 more
-
11. Re: How to use Email service in JBPM 5.x?
kersol Jul 22, 2014 10:35 AM (in response to shahdhaval2020)Hi,
To solve the error "Email must have one or more to adresses", you need to fill in the Email properties before launching the process.
You have several ways to do it :
* with Eclipse, double-click on the Email task. It opens the "Custom Work Editor" and you can then populate data,
* with Designer, look at the task properties and assign values to the different objects.
With proper values, your process should run.
Cheers.