1、问题:azkaban配置好腾讯的企业邮箱作为邮件发送者,但是zakaban的web后台直接报错误,连接超时:
javax.mail.MessagingException: Exception reading response;
13051- nested exception is:
13052- java.net.SocketTimeoutException: Read timed out
13053: at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2210)
13054: at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1950)
13055: at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
13056- at javax.mail.Service.connect(Service.java:295)
13057- at azkaban.utils.JavaxMailSender.connect(JavaxMailSender.java:34)
13058- at azkaban.utils.EmailMessage.connectToSMTPServer(EmailMessage.java:220)
13059- at azkaban.utils.EmailMessage.retryConnectToSMTPServer(EmailMessage.java:230)
13060- at azkaban.utils.EmailMessage.sendEmail(EmailMessage.java:213)
13061- at azkaban.utils.Emailer.sendEmail(Emailer.java:242)
因为腾讯的企业邮箱是用smtps协议,也就是ssl , 端口是465
2、查看源码:
azkaban mail.smtp.starttls.enable 只支持tls认证。
3、 需要在以下文件加入代码
azkaban-common/src/main/java/azkaban/utils/EmailMessage.java中
在sendEmail()方法里props的配置代码下加入以下几行代码:
import
java.security.Security;
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.socketFactory.port", "465");
效果如下图:
重新编译,部署即可用腾讯企业邮箱正常发邮件了。
我已经修改后的代码打包了,大家可以直接下载:
https://download.csdn.net/download/zsd_31/12619570