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中配置
代码如下:
- <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
- <!-- 连接数据的配置 -->
- <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?useUnicode=true"></property>
- <property name="jdbcUsername" value="root"></property>
- <property name="jdbcPassword" value="123456"></property>
- <!-- 没有表创建表 -->
- <property name="databaseSchemaUpdate" value="true"></property>
- <property name="mailServerHost" value="smtp.qq.com" />
- <property name="mailServerPort" value="587" />
- <!--默认发送方-->
- <property name="mailServerDefaultFrom" value="111111111@qq.com" />
- <!--发送方登录用户名-->
- <property name="mailServerUsername" value="11111111@qq.com"></property>
- <!--发送方登录密码-->
- <property name="mailServerPassword" value="11111111"></property>
- <!--加密方式 一定要有-->
- <property name="mailServerUseSSL" value="true" />
- </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;
}
浙公网安备 33010602011771号