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.exmail.qq.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 465, response: -1

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

# 设置邮箱主机

spring.mail.host=smtp.exmail.qq.com

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=javax.net.ssl.SSLSocketFactory

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

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

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值