700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > java 发 腾讯企业邮_JAVA使用腾讯企业邮箱发送邮件时报错Could not connect to SMTP host...

java 发 腾讯企业邮_JAVA使用腾讯企业邮箱发送邮件时报错Could not connect to SMTP host...

时间:2019-04-23 10:22:52

相关推荐

java 发 腾讯企业邮_JAVA使用腾讯企业邮箱发送邮件时报错Could not connect to SMTP host...

最近做一个邮件发送功能的时候,发现腾讯企业邮的邮箱,用java发送邮件的时候一直报错:

Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp., port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp., port: 465, response: -1

发邮件使用的spring-boot-starter-mail,配置文件如下:

# 设置邮箱主机

spring.mail.host=smtp.

spring.mail.port=465

spring.mail.protocol=smtp

# 设置用户名

spring.mail.username=xxxxxx

# 设置密码,是客户端专用密码,非网页登录密码

spring.mail.password=xxxxxx

# true代表邮箱需要认证

spring.mail.properties.mail.smtp.auth=true

#启用SSL

spring.mail.properties.mail.smtp.starttls.enable=true

spring.mail.properties.mail.smtp.starttls.required=true

查阅各种资料后发现,配置文件应当加入下面的配置:

spring.mail.properties.mail.smtp.socketFactory.class=.ssl.SSLSocketFactory

spring.mail.properties.mail.smtp.port=465

spring.mail.properties.mail.smtp.socketFactory.port=465

将这三行加入到配置文件里就可以正常发送邮件了

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。