springboot配置邮箱发送(ssl)--解决linux服务器不能发送问题

1,导包:


    
      org.springframework.boot
      spring-boot-starter-mail
    
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.构建个公共发送类


  /**
   * // 发送邮件是耗时任务,要异步发送邮箱
   */
  @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;
  }

 

你可能感兴趣的:(springboot,工具类,职霸)