码迷,mamicode.com
首页 > 编程语言 > 详细

springboot发送邮件

时间:2018-08-14 21:06:39      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:href   art   style   www   邮件发送   ***   hello   security   发送邮件   

springboot发送邮件

1.依赖文件pom.xml:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

2.配置文件:

#####163邮箱########
spring.mail.host=smtp.163.com
spring.mail.username=xxxxxxx@163.com
#163邮箱授权码
spring.mail.password=*********
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

3.controller:

@RestController
public class HelloController {

    @Autowired
    private JavaMailSender mailSender;
    
     @Value("${spring.mail.username}")
    private String username;
@RequestMapping(
"/email") public String sendSimpleMail() throws Exception { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(username); message.setTo("xxxxxxxx@qq.com"); message.setSubject("主题:发送邮件"); message.setText("测试邮件发送成功"); mailSender.send(message); return "success"; } }

如果报 535 认证失败,将下载后的local_policy.jarUS_export_policy.jar替换到JDK1.8的jre\lib\security文件夹即可。 

下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

springboot发送邮件

标签:href   art   style   www   邮件发送   ***   hello   security   发送邮件   

原文地址:https://www.cnblogs.com/heqiyoujing/p/9477490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!