activiti5-springboot配置邮件的自动发送邮件

请结合http://www.cnblogs.com/5769-ftl/p/9007998.html配置服务器)

1)配置Foxmail

2)

 

3)

4)

5)

 

配置发送activiti 邮件端号

@Configuration
public class EmailUtil implements ProcessEngineConfigurationConfigurer {

@Override
public void configure(SpringProcessEngineConfiguration process) {
process.setMailServerPort(25);

}

}
6)测试代码

@Autowired

private RepositoryService respository;

@Autowired
private RuntimeService runTimeService;
@Test
public void mailTest() {
respository.createDeployment()
.addClasspathResource("emailTest.bpmn")
.deploy();

ProcessDefinition pd = respository.createProcessDefinitionQuery()
.processDefinitionKey("myProcess")
.latestVersion()
.singleResult();
System.out.println(pd.getKey());
ProcessInstance pi = runTimeService.startProcessInstanceById(pd.getId());

}

7)这里使用的是springboot框架

如果是spring需要在xml中配置

代码如下:

  1. <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">  
  2.         <!-- 连接数据的配置 -->  
  3.         <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>  
  4.         <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?useUnicode=true"></property>  
  5.         <property name="jdbcUsername" value="root"></property>  
  6.         <property name="jdbcPassword" value="123456"></property>  
  7.         <!-- 没有表创建表 -->  
  8.         <property name="databaseSchemaUpdate" value="true"></property>  
  9.         <property name="mailServerHost" value="smtp.qq.com" />  
  10.         <property name="mailServerPort" value="587" />   
  11.         <!--默认发送方-->  
  12.         <property name="mailServerDefaultFrom" value="111111111@qq.com" />  
  13.         <!--发送方登录用户名-->  
  14.         <property name="mailServerUsername" value="11111111@qq.com"></property>    
  15.         <!--发送方登录密码-->  
  16.         <property name="mailServerPassword" value="11111111"></property>   
  17.         <!--加密方式 一定要有-->  
  18.         <property name="mailServerUseSSL" value="true" />  
  19.   
  20.  </bean>  

       8)这里配置端口号使用到了接口注入属性的方式 :实现特定的接口

          ①任意环境 获取spring  核心对象 ApplicationContext可以使用这种方式:

   ② web环境可以使用spring提供的 工具类  WebApplicationContextUtils 其中有一个方法:

public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc)
throws IllegalStateException {

WebApplicationContext wac = getWebApplicationContext(sc);
if (wac == null) {
throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
}
return wac;
}

 

posted on 2018-05-08 20:32  把握现在☝  阅读(499)  评论(0)    收藏  举报

导航