Azkaban Connecting to SMTP server failed

1.啟用azkaban的郵件配置在 azkaban.properties中定義發(fā)送郵箱

mail.sender=xx@qq.com

mail.host=smtp.exmail.qq.com

mail.user=xx@qq.com

mail.port=465

mail.password=xxxxxx

#job.failure.email=xx@qq.com

#job.success.email=xx@qq.com

mail.tls=true

2.錯(cuò)誤如下

ERROR [EmailMessage] [Azkaban] Connecting to SMTP server failed, attempt: 0

? ? javax.mail.MessagingException: Exception reading response;

? ? nested exception is:

? ? java.net.SocketTimeoutException: Read timed out

? ? at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2210)

? ? at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1950)

? ? at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)

? ? at javax.mail.Service.connect(Service.java:295)

? ? at azkaban.utils.EmailMessage.connectToSMTPServer(EmailMessage.java:226)

? ? at azkaban.utils.EmailMessage.retryConnectToSMTPServer(EmailMessage.java:236)

? ? at azkaban.utils.EmailMessage.sendEmail(EmailMessage.java:219)

? ? at azkaban.utils.Emailer.sendSuccessEmail(Emailer.java:231)

3.解決方式:修改源碼并重新編譯azkaban/azkaban-common/src/main/java/azkaban/utils/EmailMessage.java即可

//---------------NEW ADD START----------------------------------------

import com.sun.mail.util.MailSSLSocketFactory;

import java.security.GeneralSecurityException;

//---------------NEW ADD END----------------------------------------


public void sendEmail() throws MessagingException {

? ? ? ? ? checkSettings();

? ? ? ? ? final Properties props = new Properties();

? ? ? ? ? if (this._usesAuth) {

? ? ? ? ? ? ? props.put("mail." + protocol + ".auth", "true");

? ? ? ? ? ? ? props.put("mail.user", this._mailUser);

? ? ? ? ? ? ? props.put("mail.password", this._mailPassword);

? ? ? ? ? } else {

? ? ? ? ? ? ? props.put("mail." + protocol + ".auth", "false");

? ? ? ? ? }

? ? ? ? ? props.put("mail." + protocol + ".host", this._mailHost);

? ? ? ? ? props.put("mail." + protocol + ".port", this._mailPort);

? ? ? ? ? props.put("mail." + protocol + ".timeout", _mailTimeout);

? ? ? ? ? props.put("mail." + protocol + ".connectiontimeout", _connectionTimeout);

? ? ? ? ? props.put("mail.smtp.starttls.enable", this._tls);

? ? ? ? ? props.put("mail.smtp.ssl.trust", this._mailHost);

//---------------NEW ADD START----------------------------------------

? ? ? ? ? MailSSLSocketFactory sf;

? ? ? ? ? try {

? ? ? ? ? ? ? sf = new MailSSLSocketFactory();

? ? ? ? ? ? ? sf.setTrustAllHosts(true);

? ? ? ? ? ? ? props.put("mail.smtp.ssl.enable", "true");

? ? ? ? ? ? ? props.put("mail.smtp.ssl.socketFactory", sf);

? ? ? ? ? } catch (GeneralSecurityException e) {

? ? ? ? ? ? ? e.printStackTrace();

? ? ? ? ? }

//------------NEW ADD END--------------------------------------------

? ? ? ? ? final Session session = Session.getInstance(props, null);

? ? ? ? ? final Message message = new MimeMessage(session);

? ? ? ? ? final InternetAddress from = new InternetAddress(this._fromAddress, false);

? ? ? ? ? message.setFrom(from);

? ? ? ? ? for (final String toAddr : this._toAddress) {

? ? ? ? ? ? ? message.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddr, false));

? ? ? ? ? }

? ? ? ? ? message.setSubject(this._subject);

? ? ? ? ? message.setSentDate(new Date());

? ? ? ? ? if (this._attachments.size() > 0) {

? ? ? ? ? ? ? final MimeMultipart multipart = this._enableAttachementEmbedment ? new MimeMultipart("related")

? ? ? ? ? ? ? ? ? ? ? ? : new MimeMultipart();

? ? ? ? ? ? ? final BodyPart messageBodyPart = new MimeBodyPart();

? ? ? ? ? ? ? messageBodyPart.setContent(this._body.toString(), this._mimeType);

? ? ? ? ? ? ? multipart.addBodyPart(messageBodyPart);

? ? ? ? ? ? ? // Add attachments

? ? ? ? ? ? ? for (final BodyPart part : this._attachments) {

? ? ? ? ? ? ? ? ? ? multipart.addBodyPart(part);

? ? ? ? ? ? ? }

? ? ? ? ? ? ? message.setContent(multipart);

? ? ? ? ? } else {

? ? ? ? ? ? ? message.setContent(this._body.toString(), this._mimeType);

? ? ? ? ? }

? ? ? ? ? final SMTPTransport t = (SMTPTransport) session.getTransport(protocol);

? ? ? ? ? retryConnectToSMTPServer(t);

? ? ? ? ? retrySendMessage(t, message);

? ? ? ? ? t.close();

? ? }

4.編譯命令:

./gradlew build installDist -x test #此命令可以跳過(guò)測(cè)試

參考:?https://www.pomelolee.com/1819.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容