Springboot集成Java mail配置

springboot 集成java mail 發郵件時報錯:

Caused by: javax.mail.MessagingException: Could not connect to SMTP host: xxxxx, port: 465, response: -1

查詢發現發郵件的服務器是https的,

查看javamail的源碼發現可以添加SSLSocketFactory

if (sf == null) {

String sfClass =

props.getProperty(prefix + ".socketFactory.class");

sf = getSocketFactory(sfClass);

sfErr = "socket factory class " + sfClass;

}


需要添加如下配置mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory"

spring

mail:

host:

port: 465

username:

password:

properties: {mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory"}

//同樣可以配置連接、Read超時時間properties: {mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory",mail.smtp.connectiontimeout: "10000", mail.smtp.timeout: "10000"}

default-encoding: UTF-8


分享到:


相關文章: