您的位置 首页 java

Springboot集成Java mail配置

springboot 集成java mail 发邮件时报错:

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

查询发现发邮件的服务器是https的,

查看javamail的源码发现可以添加 ssl SocketFactory

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

文章来源:智云一二三科技

文章标题:Springboot集成Java mail配置

文章地址:https://www.zhihuclub.com/191629.shtml

关于作者: 智云科技

热门文章

网站地图