-
Notifications
You must be signed in to change notification settings - Fork 31
javayh mail starter 说明
杨海吉 edited this page Apr 5, 2020
·
2 revisions
javayh-mail-starter 是项目邮件处理的核心依赖
<dependency>
<groupId>com.javayh</groupId>
<artifactId>javayh-mail-starter</artifactId>
</dependency>
在启动类添加 @EnableMail 开启对邮件的支持 在最新版本中,@EnableMail已经废弃,实现类自动注入
@EnableMail
@JavayhBootApplication
public class MailApplication {
public static void main(String[] args) {
SpringApplication.run(MailApplication.class,args);
}
}
@Autowired(required = false)
private MailSend mailSenderUtil;
@PostMapping(value = "send")
public ResultData send(@RequestBody MailDO mailDO){
Map<String,Object> map = new HashMap<>();
map.put("username","Yang haiji");
mailDO.setAttachment(map
mailSenderUtil.sendTextMail(mailDO);
return ResultData.success();
}
@Autowired(required = false)
private MailSend mailSenderUtil;
@PostMapping(value = "send")
public ResultData send(@RequestBody MailDO mailDO){
Map<String,Object> map = new HashMap<>();
map.put("username","Yang haiji");
mailDO.setAttachment(map);
mailDO.setTemplateName("HelloMail");
mailSenderUtil.sendTextMail(mailDO);
return ResultData.success();
}
注
发送模板需要添加配置
thymeleaf:
enabled: true
mode: LEGACYHTML5
encoding: UTF-8
prefix: classpath:/templates/ # 模板存放在资源目录的 templates/ 文件下
suffix: .html # 模板后缀
check-template-location: true
check-template: false
cache: false # 调试时关闭缓存
servlet:
content-type: text/html
详细使用见,javayh-demo-mail
关注 Java有货领取更多资料
联系小编。微信:372787553,带您进群互相学习
左侧小编微信,右侧获取免费资料
- SpringCloud 自定义封装架构https://github.com/Dylan-haiji/javayh-platform
- Java 设计模式学习代码 https://github.com/Dylan-haiji/design-pattern
- SpringCloud学习代码: https://github.com/Dylan-haiji/javayh-cloud
- AlibabaCloud学习代码:https://github.com/Dylan-haiji/javayh-cloud-nacos
- SpringBoot+Mybatis 多数据源切换:https://github.com/Dylan-haiji/javayh-boot-data-soure
- Redis、Mongo、Rabbitmq、Kafka学习代码: https://github.com/Dylan-haiji/javayh-middleware
- SpringBoot+SpringSecurity实现自定义登录学习代码:https://github.com/Dylan-haiji/javayh-distribution