解决: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=[email protected] spring.mail.password=授权码 spring.mail.default-encoding=UTF-8 mail.fromMail.addr=[email protected]//说明发送地址 #解决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("[email protected]");//发送者 message.setTo("[email protected]");//接受者 message.setSubject("主题:简单邮件"); message.setText("测试邮件内容1"); mailSender.send(message); }
测试结果: