问题描述
腾讯企业邮箱第三方发送邮件文档:https://open.work.weixin.qq.com/help?person_id=0&doc_id=423&helpType=exmail
发送邮件服务器:smtp.exmail.qq.com ,使用SSL,端口号465,所以如下代码配置各项属性:
Properties props = new Properties(); props.put("mail.smtp.host", "smtp.exmail.qq.com"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); props.put("mail.smtp.ssl.enable", "true");
但是在有的Linux服务器上却无法发送邮件,报错提示:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 465, response: -1
服务器上用telnet smtp.exmail.qq.com 465端口却是通的!
问题解决
代码里把端口465的配置去掉,就可以了!(文档的大坑,躲开!)
Properties props = new Properties(); props.put("mail.smtp.host", "smtp.exmail.qq.com"); props.put("mail.smtp.auth", "true"); // props.put("mail.smtp.port", "465"); //去掉这行就可以正常发送了 props.put("mail.smtp.ssl.enable", "true");
文章评论