1、修改jbpm.mail.properties,修改后的内容如下:
mail.smtp.host=smtp.163.com
mail.smtp.port=25
mail.from=userName@163.com
mail.smtp.auth= true
mail.debug=true
2、修改jbpm.cfg.xml,修改后内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.customer.cfg.xml" /> <!--替换jbpm.default.cfg.xml,主要功能是这样修改mail-Server相关属性方便-->
<import resource="jbpm.businesscalendar.cfg.xml" />
<import resource="jbpm.tx.hibernate.cfg.xml" />
<import resource="jbpm.jpdl.cfg.xml" />
<import resource="jbpm.bpmn.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
<!-- Job executor is excluded for running the example test cases. -->
<!-- To enable timers and messages in production use, this should be included. -->
<!--
<import resource="jbpm.jobexecutor.cfg.xml" />
-->
</jbpm-configuration>
3、在classpath下建立文件jbpm.customer.cfg.xml,复制jbpm.default.cfg.xml中的内容到新建新建的文件中,修改其中
<mail-session>
<mail-server>
<session-properties resource="jbpm.mail.properties" />
<authenticator class="com.cqs.mail.MyAuthenticator">
<field name="userName"><string value="cuitsingsh"/></field>
<field name="password"><string value="cqsztt"/></field>
</authenticator>
</mail-server>
</mail-session>
4、增加验证类MyAuthenticator如下:
package com.cqs.mail;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MyAuthenticator extends Authenticator{
private String userName;
private String password;
public MyAuthenticator() {
System.out.println("myAuthenticator is construct");
}
@Override
protected PasswordAuthentication getPasswordAuthentication() {
// TODO Auto-generated method stub
return new PasswordAuthentication(userName, password);
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
6、测试代码如下:
package com.cqs.test;
import java.util.ArrayList;
import org.jbpm.test.JbpmTestCase;
public class TestSendMail extends JbpmTestCase{
public void test() {
String deployId = repositoryService.createDeployment()
.addResourceFromClasspath("send_mail.jpdl.xml").deploy();
//发起流程
executionService.startProcessInstanceByKey("send_mail");
if(registeredDeployments == null) {//registeredDeployments是JbpmTestCase用来删除部署的流程用的
registeredDeployments = new ArrayList<String>();
}
registeredDeployments.add(deployId);
}
}
Eclipse版本:eclipse-java-galileo-SR2-win32
jbpm版本:4.4
经过163邮箱试验成
摘自:http://blog.csdn.net/kingcqs/archive/2010/12/18/6084349.aspx