springboot configured to send mail (ssl) - linux server can not resolve a question

1, the leader packet:

<!-- mail发送 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
2,配置properties文件:
spring.mail.host=smtp.qq.com
spring.mail.username=******@qq.com
#密码指得是动态密码,qq邮箱的话在设置里打开,会有个动态smtp码.
spring.mail.password=******
spring.mail.protocol=smtps
spring.mail.test-connection=false
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

# ssl 配置  (非ssl发送一般是25端口,linux服务器一般都是禁用的,所以要切换465)
spring.mail.port=465
spring.mail.default-encoding=UTF-8
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.imap.ssl.socketFactory.fallback=false
spring.mail.properties.mail.smtp.ssl.socketFactory.class=com.fintech.modules.base.util.mail.MailSSLSocketFactory

3. Construction of public transmission class


  /**
   * // 发送邮件是耗时任务,要异步发送邮箱
   */
  @Override
  @Async
  public boolean sendMail(Mail mail) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(mail.getSender());
    message.setTo(mail.getReceiver());
    message.setSubject(mail.getSubject());
    message.setText(mail.getText());
    mailSender.send(message);
    return true;
  }

 

Guess you like

Origin blog.csdn.net/weixin_42533856/article/details/95322199