Jbpm4.4 邮件模版的相关配置

Step1:JBPM的邮件发送功能,需要我们自己实现用户认证的类,如下:

public class EmailAuthenticator extends Authenticator{
	
	public EmailAuthenticator() {
		System.out.println("custom email authenticator is loading...");
	}
	
	private String userName;
	private String password;
	
	@Override
	protected PasswordAuthentication getPasswordAuthentication() {
		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;
	}	
}


Step2:在classpath下创建用以替换jbpm.default.cfg.xml的文件,我这个地方叫jbpm.customer.cfg.xml

可先直接将jbpm.default.cfg.xml中的内容,复制到jbpm.customer.cfg.xml中,然后修改mail-session部分如下:

    
      
        	      		
         
         	 
         	
        
      
    


Ste3:创建jbpm.mail.properties文件如下:

mail.smtp.auth=true
mail.smtp.host=smtp.189.cn
mail.smtp.port=25
[email protected]

Step4:修改jbpm.cfg.xml文件内容如下(用Step2中创建的配置文件替换jbpm.default.cfg.xml):

  
  
  
  
  
  
  

Ste5:依然在classpath下创建发送email的模版文件jbpm.mail.templates.xml如下(此处创建了两个模版):




	
		 
		    				
${task.name} [test]做个好汉子,热血热肠热
 
  
Step7:创建测试用户

		IdentityService identityService = processEngine.getIdentityService();
//		identityService.createUser("andy", "andy", "xu", "[email protected]");
		identityService.createUser("sandy", "sandy", "lau", "[email protected]");


Step8:测试-->先测试task节点的notification功能,定义测试流程如下:


   
      
      
   
        
          		
   
     
-当开启这个测试流程的时候, 用户andy就能在自己的邮箱[email protected]中收到邮件了.. 

Step9:测试-->测试email节点的邮件接收功能,定义测试流程如下:


   
      
   
   
    
         		
    

开启流程:

ExecutionService es = processEngine.getExecutionService();		
		Map vars = new HashMap();
		vars.put("mailTo", "andy,sandy");		
		ProcessInstance processInstance = es.startProcessInstanceByKey("mailnotify", vars);
-这样,[email protected]以及[email protected]就都能收模版为enotify-template的邮件了..

你可能感兴趣的:(Java)