spring boot发简单文本邮件
2024-09-06 07:35:19
首先要去邮箱打开POP3/SMTP权限:
然后会提供个授权码,用来发送邮件。忘记了,可以点生成授权码再次生成。
1、引入spring boot自带的mail依赖,这里版本用的:<spring-boot.version>1.4.3.RELEASE</spring-boot.version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>${spring-boot.version}</version>
<scope>provided</scope>
</dependency>
2、spring boot配置文件添加邮箱参数信息
spring.mail.host=smtp.qq.com
spring.mail.username=你的qq号码@qq.com
spring.mail.password=qq邮箱开启SMTP提供的授权码(注意:不是你的qq邮箱密码)
#下面一般不用动
spring.mail.default-encoding=${spring.http.encoding.charset}
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
3、测试发送
@Autowired
private JavaMailSender mailSender; @Value("${spring.mail.username}")
private String from; SimpleMailMessage smm = new SimpleMailMessage();
smm.setFrom(from);
smm.setTo("发送方邮件地址");
smm.setSubject("springboot测试邮件");
smm.setText("简单文本邮件测试发送!");
mailSender.send(smm);
最新文章
- 当我谈 ";加班有罪"; 我在谈什么?
- Ubuntu杂记——Ubuntu自带拼音输入发杂乱不堪
- c++ DLL->;DEF->;LIB
- VIM使用(二) 浏览内核源代码
- 安装 vue.js和第一个hello world
- webstorm配置scss自动编译路径
- Tomcat 使用说明
- channelartlist添加栏目链接
- maven search
- ASP.NET MVC5 学习笔记-4 OWIN和Katana
- Beautifulsoup 和selenium 的查询
- JAVA基础第六组(5道题)
- 《前端之路》之三 数组的属性 &;&; 操作方法(上)
- 52 和 52Rc 通过IIC写入数据
- wx小程序-音频视频!
- C++ 跨语言调用 Java
- 【待完成】[MapReduce_9] MapReduce 的 Shuffle 机制
- SSH框架搭建demo
- 使用Gitblit 在Windows2008 r2上部署Git Server(完整版)
- lua内存管理
热门文章
- CSS——背景及应用
- 字符串匹配dp+bitset,滚动数组优化——hdu5745(经典)
- NX二次开发-获取面的法向向量UF_MODL_ask_face_data
- 拾遗:Perl 基础语法
- postgresql+java数据类型对照
- 17-MySQL-Ubuntu-数据表的查询-分页(六)
- java获得磁盘、网络实时I/O速率
- iOS开发系列-Runtime运用场景
- RabbitMQ学习第一记:用java连接RabbitMQ
- Appium 微信 webview 的自动化技术