腾讯企业邮箱发送邮件失败

一直使用的腾讯企业邮箱,但是最近发现发送邮件全是失败的,提示:

javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 25;
  nested exception is:
	java.net.ConnectException: 连接超时 (Connection timed out)
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
	at javax.mail.Service.connect(Service.java:317)
	at javax.mail.Service.connect(Service.java:176)
	at javax.mail.Service.connect(Service.java:125)
	at javax.mail.Transport.send0(Transport.java:194)
	at javax.mail.Transport.send(Transport.java:124)

原因就是现在很多企业邮箱为了安全都使用了SSL加密连接了:https://service.exmail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1000585,所以端口号改了465

修改端口后又有一下错误:

javax.mail.MessagingException: Could not connect to SMTP host: smtp.exmail.qq.com, port: 465, response: -1
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1949)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
	at javax.mail.Service.connect(Service.java:317)
	at javax.mail.Service.connect(Service.java:176)
	at javax.mail.Service.connect(Service.java:125)
	at javax.mail.Transport.send0(Transport.java:194)
	at javax.mail.Transport.send(Transport.java:124)

这个是少了一个配置mail.smtp.ssl.enable=true,在原来的配置上加上这个就OK了。