解决:Caused by: javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered
springboot发送qq邮件出现:Caused by: javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28
1.QQ邮箱发送的时候会出现SSL连接失败的情况,主要是我用的jdk 8,里面ssl认证的问题,解决的办法是替换目录 %JAVA_HOME%\jre\lib\security里的local_policy.jar,US_export_policy.jar
下载连接:http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
2.如果1没有解决问题的话,那么就在application.properties加上:
spring.application.name=spirng-boot-mail
spring.mail.host=smtp.qq.com
spring.mail.username=xxx@qq.com
spring.mail.password=授权码
spring.mail.default-encoding=UTF-8
mail.fromMail.addr=xxx@qq.com//说明发送地址
#解决530问题,加上以下3句
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
再次测试
@Test
public void sendSimpleMail() throws Exception {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("xxx@qq.com");//发送者
message.setTo("xxx@qq.com");//接受者
message.setSubject("主题:简单邮件");
message.setText("测试邮件内容1");
mailSender.send(message);
}
测试结果:
我的座右铭:不会,我可以学;落后,我可以追赶;跌倒,我可以站起来;我一定行。
还没有评论,来说两句吧...