解决:Caused by: javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered

待我称王封你为后i 2022-05-25 01:28 607阅读 0赞

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

70

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加上:

  1. spring.application.name=spirng-boot-mail
  2. spring.mail.host=smtp.qq.com
  3. spring.mail.username=xxx@qq.com
  4. spring.mail.password=授权码
  5. spring.mail.default-encoding=UTF-8
  6. mail.fromMail.addr=xxx@qq.com//说明发送地址
  7. #解决530问题,加上以下3句
  8. spring.mail.properties.mail.smtp.auth=true
  9. spring.mail.properties.mail.smtp.starttls.enable=true
  10. spring.mail.properties.mail.smtp.starttls.required=true

再次测试

  1. @Test
  2. public void sendSimpleMail() throws Exception {
  3. SimpleMailMessage message = new SimpleMailMessage();
  4. message.setFrom("xxx@qq.com");//发送者
  5. message.setTo("xxx@qq.com");//接受者
  6. message.setSubject("主题:简单邮件");
  7. message.setText("测试邮件内容1");
  8. mailSender.send(message);
  9. }

测试结果:

70 1

我的座右铭:不会,我可以学;落后,我可以追赶;跌倒,我可以站起来;我一定行。

发表评论

表情:
评论列表 (有 0 条评论,607人围观)

还没有评论,来说两句吧...

相关阅读