欢迎访问『www.cnblogs.com/blog-ice』
注意:绿色标注的163邮箱必须一致
1.依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> 2.配置 spring.mail.host=smtp.163.com spring.mail.username=xxx@163.com spring.mail.password=密码或授权码 3.发送代码 @Autowired private MailSender mailSender; @GetMapping("/email") public String sendEmail() throws MessagingException { String to = "xxx@qq.com"; String subject = "Test"; String text = "This is a test from spring boot"; SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setFrom("xxx@163.com"); simpleMailMessage.setSubject(subject); simpleMailMessage.setTo(to); simpleMailMessage.setText(text); mailSender.send(simpleMailMessage); return "done"; }

 

posted on 2022-02-17 09:03  仙路尽头谁为峰  阅读(44)  评论(0编辑  收藏  举报
这里是自由发挥的天堂