springboot与任务(邮件任务)
2024-09-30 19:08:50
- 邮件发送需要引入spring-boot-starter-mail
- Spring Boot 自动配置MailSenderAutoConfiguration
- 定义MailProperties内容,配置在application.yml中
- 自动装配JavaMailSender
测试邮件发送
- pom文件配置:
<!--邮件发送-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency> - applicationproperties配置:
spring.mail.username=442624769@qq.com
#自己邮箱的授权码
spring.mail.password=lufufllqrylobijg
spring.mail.host=smtp.qq.com #开启安全(有时需要)
spring.mail.properties.mail.smtp.ssl.enable=true - 测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
public class Springboot04TaskApplicationTests { @Autowired
JavaMailSenderImpl mailSender; @Test
public void contextLoads() {
//创建一个简单的消息邮件
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setSubject("通知-今晚开会");
simpleMailMessage.setText("今晚7点30开会"); simpleMailMessage.setTo("2163370170@qq.com");
simpleMailMessage.setFrom("442624769@qq.com");
mailSender.send(simpleMailMessage);
} @Test
public void test02() throws MessagingException {
//创建一个复杂的消息邮件 MimeMessage mimeMessage = mailSender.createMimeMessage();
//准备上传文件
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
//邮件设置
helper.setSubject("通知-今晚开会");
//设置写的这段内容为html
helper.setText("<b style='color:red'>今天7:30开会</b>",true); helper.setTo("2163370170@qq.com");
helper.setFrom("442624769@qq.com"); //上传文件
helper.addAttachment("1.png",new File("C:\\Users\\44262\\Desktop\\1.png")); mailSender.send(mimeMessage); }
}
最新文章
- MyEclipse新建web project和navicat110_mysql_en工具
- autobench 测试笔记
- Android 注解工具 ButterKnife
- java数据结构
- 怎么通过activity里面的一个按钮跳转到另一个fragment(android FragmentTransaction.replace的用法介绍)
- python中列表和元组的使用方法和区别
- 安装python2.7.13-64bit &; Pycharm在两个python版本之间切换
- PHP初体验
- 2017";百度之星";程序设计大赛 - 资格赛【1001 Floyd求最小环 1002 歪解(并查集),1003 完全背包 1004 01背包 1005 打表找规律+卡特兰数】
- 微软Azure AspNetCore微服务实战第2期
- linux C中调用shell命令和运行shell脚本
- VUE v-for问题
- 第一模块 Python开发入门
- An optimizer that trains as fast as Adam and as good as SGD. https://www.luolc.com/publications/ad…
- Flink安装启动
- 如何恢复windows的exe文件的默认打开方式
- Java读取maven目录下的*.properties配置文件
- vuejs code splitting with webpack 3种模式
- Android笔记-1
- Linux对包管理阐述
热门文章
- React:styled-components
- Selenium(一)---Selenium的安装和使用
- 如何去掉vue路由中的#
- HTML_CSS使用
- iOS开发系列-NSFileManager
- GetOpenFilename的基本用法
- 2019牛客暑期多校训练营(第八场) E 线段树+可撤销并查集
- Android studio 添加引用Module项目 与 设置Module项目的Libs的Jar在主项目里使用
- CSS——精灵技术
- 最大流Dinic算法的一些优化 [网络流][最大流]