SpringBoot+JavaMailSender+ 腾讯企业邮箱配置
1. 引入spring-boot-starter-mail 依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
2. 在application.yml配置邮箱基本信息
spring:
mail:
host: smtp.exmail.qq.com
port: 465
username: [email protected]
password: xxxx
protocol: smtp
properties:
mail:
smtp:
auth: true
ssl:
enable: true
socketFactory:
class: com.sun.mail.util.MailSSLSocketFactory
fallback: false
3. 实现代码
@Autowired
JavaMailSender javaMailSender;
public void testSend() {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("[email protected]"); //发送者邮箱地址 此地址一定要和yml邮箱一致
message.setTo("[email protected]"); //收件人邮箱地址