目录
接着后就会有对应的密钥了
这里的建议是 2.0系列的Springboot版本用低一点的邮件依赖
-
org.springframework.boot -
spring-boot-starter-mail -
2.7.18
- spring:
- mail:
- default-encoding: UTF-8
- host: smtp.qq.com
- port: 587
- username: 你的邮件
- password: 刚刚QQ生成的密钥
- properties:
- mail:
- smtp:
- starttls:
- enable: true
- auth: true
- socketFactory:
- class: javax.net.ssl.SSLSocketFactory
- debug: true
为了方便直接写在 控制层 了
- package com.takem.controller;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.mail.SimpleMailMessage;
- import org.springframework.mail.javamail.JavaMailSender;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
-
- @RestController
- public class EmailController {
-
- @Autowired
- private JavaMailSender mailSender;
-
- @GetMapping("/email")
- public String sendSimpleMessage() {
- SimpleMailMessage mailMessage = new SimpleMailMessage();
- mailMessage.setFrom("自己的邮箱");
- mailMessage.setTo("别人的邮箱");
- mailMessage.setText("这是内容");
- mailMessage.setSubject("这是邮件标题");
- mailSender.send(mailMessage);
- return "====完成发送!====";
- }
- }
以自己发给自己为例