<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: How to use Email service in JBPM 5.x?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/valle">valle</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/755868#755868">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class ProcessMain {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public static final void main(String[] args) throws Exception {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // load up the knowledge base</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; KnowledgeBase kbase = readKnowledgeBase();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // email</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; EmailWorkItemHandler emailHandler = new EmailWorkItemHandler();</p><p><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; emailHandler.setConnection("smtp.gmail.com", "465", "</span><a class="jive-link-email-small" href="mailto:myusername@gmail.com" target="_blank">myusername@gmail.com</a><span>", "mypassword");</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; emailHandler.getConnection();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ksession.getWorkItemManager().registerWorkItemHandler("Email", emailHandler);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // start a new process instance</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ksession.startProcess("com.sample.bpmn.hello");</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private static KnowledgeBase readKnowledgeBase() throws Exception {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return kbuilder.newKnowledgeBase();</p><p>&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>and this is the exception message:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Exception in thread "main" org.jbpm.workflow.instance.WorkflowRuntimeException: [com.sample.bpmn.hello:1 - Email:4] -- Unable to send email</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:130)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerNodeInstance(NodeInstanceImpl.java:205)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:164)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:124)</p><p>&#160;&#160;&#160; at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)</p><p>&#160;&#160;&#160; at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:303)</p><p>&#160;&#160;&#160; at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:168)</p><p>&#160;&#160;&#160; at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:138)</p><p>&#160;&#160;&#160; at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:130)</p><p>&#160;&#160;&#160; at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1077)</p><p>&#160;&#160;&#160; at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:315)</p><p>&#160;&#160;&#160; at com.sample.ProcessMain.main(ProcessMain.java:29)</p><p>Caused by: java.lang.RuntimeException: Unable to send email</p><p>&#160;&#160;&#160; at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:65)</p><p>&#160;&#160;&#160; at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:37)</p><p>&#160;&#160;&#160; at org.jbpm.process.workitem.email.EmailWorkItemHandler.executeWorkItem(EmailWorkItemHandler.java:68)</p><p>&#160;&#160;&#160; at org.drools.process.instance.impl.DefaultWorkItemManager.internalExecuteWorkItem(DefaultWorkItemManager.java:70)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:105)</p><p>&#160;&#160;&#160; at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:124)</p><p>&#160;&#160;&#160; ... 14 more</p><p>Caused by: java.lang.RuntimeException: Connection failure</p><p>&#160;&#160;&#160; at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:59)</p><p>&#160;&#160;&#160; ... 19 more</p><p>Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1</p><p>&#160;&#160;&#160; at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1922)</p><p>&#160;&#160;&#160; at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)</p><p>&#160;&#160;&#160; at javax.mail.Service.connect(Service.java:295)</p><p>&#160;&#160;&#160; at org.jbpm.process.workitem.email.SendHtml.sendHtml(SendHtml.java:56)</p><p>&#160;&#160;&#160; ... 19 more</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/755868#755868">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>