qxiong522 opened a new issue #5661:
URL: https://github.com/apache/dolphinscheduler/issues/5661
**Describe the question**
邮件告警发送失败
1. 以下配置:
```
MAIL_PROTOCOL=SMTP
MAIL_SERVER_HOST=smtp.163.com
MAIL_SERVER_PORT=25
[email protected]
[email protected]
MAIL_PASSWD=xxxxxx
MAIL_SMTP_STARTTLS_ENABLE=false
MAIL_SMTP_SSL_ENABLE=false
MAIL_SMTP_SSL_TRUST=
```
可以发送成功
如果 `MAIL_SMTP_STARTTLS_ENABLE=true` 失败
失败代码:
```
dolphinscheduler-alert_1 | org.apache.commons.mail.EmailException: Sending
the email to the following server failed : smtp.163.com:25
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.send(Email.java:1496)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.utils.MailUtils.getStringObjectMap(MailUtils.java:321)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.utils.MailUtils.sendMails(MailUtils.java:136)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.manager.EmailManager.send(EmailManager.java:39)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.plugin.EmailAlertPlugin.process(EmailAlertPlugin.java:101)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.runner.AlertSender.run(AlertSender.java:84)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.AlertServer.start(AlertServer.java:82)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.AlertServer.main(AlertServer.java:89)
dolphinscheduler-alert_1 | Caused by: javax.mail.MessagingException: Could
not convert socket to TLS
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2155)
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:752)
dolphinscheduler-alert_1 | at
javax.mail.Service.connect(Service.java:388)
dolphinscheduler-alert_1 | at
javax.mail.Service.connect(Service.java:246)
dolphinscheduler-alert_1 | at
javax.mail.Service.connect(Service.java:195)
dolphinscheduler-alert_1 | at
javax.mail.Transport.send0(Transport.java:254)
dolphinscheduler-alert_1 | at
javax.mail.Transport.send(Transport.java:124)
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
dolphinscheduler-alert_1 | ... 8 common frames omitted
dolphinscheduler-alert_1 | Caused by: java.io.IOException: Server is not
trusted: smtp.163.com
dolphinscheduler-alert_1 | at
com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:638)
dolphinscheduler-alert_1 | at
com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:553)
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2150)
dolphinscheduler-alert_1 | ... 15 common frames omitted
```
2. 更换以下配置
```
MAIL_PROTOCOL=SMTP
MAIL_SERVER_HOST=smtp.partner.outlook.cn
MAIL_SERVER_PORT=25 (587 也试了,错误一样)
[email protected]
[email protected]
MAIL_PASSWD=xxxxx
MAIL_SMTP_STARTTLS_ENABLE=false
MAIL_SMTP_SSL_ENABLE=false
MAIL_SMTP_SSL_TRUST=
```
发送失败
```
dolphinscheduler-alert_1 | org.apache.commons.mail.EmailException: Sending
the email to the following server failed : smtp.partner.outlook.cn:25
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.send(Email.java:1496)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.utils.MailUtils.getStringObjectMap(MailUtils.java:321)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.utils.MailUtils.sendMails(MailUtils.java:136)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.manager.EmailManager.send(EmailManager.java:39)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.plugin.EmailAlertPlugin.process(EmailAlertPlugin.java:101)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.runner.AlertSender.run(AlertSender.java:84)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.AlertServer.start(AlertServer.java:82)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.AlertServer.main(AlertServer.java:89)
dolphinscheduler-alert_1 | Caused by:
com.sun.mail.smtp.SMTPSendFailedException: 451 5.7.3 STARTTLS is required to
send mail [BJXPR01CA006.CHNPR01.prod.partner.outlook.cn]
dolphinscheduler-alert_1 |
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2358)
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1823)
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1300)
dolphinscheduler-alert_1 | at
javax.mail.Transport.send0(Transport.java:255)
dolphinscheduler-alert_1 | at
javax.mail.Transport.send(Transport.java:124)
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
dolphinscheduler-alert_1 | ... 8 common frames omitted
```
按照提示开启 tls `MAIL_SMTP_STARTTLS_ENABLE=true` 还是失败
失败原因:
```
dolphinscheduler-alert_1 | org.apache.commons.mail.EmailException: Sending
the email to the following server failed : smtp.partner.outlook.cn:25
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.send(Email.java:1496)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.utils.MailUtils.getStringObjectMap(MailUtils.java:321)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.utils.MailUtils.sendMails(MailUtils.java:136)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.manager.EmailManager.send(EmailManager.java:39)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.plugin.EmailAlertPlugin.process(EmailAlertPlugin.java:101)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.runner.AlertSender.run(AlertSender.java:84)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.AlertServer.start(AlertServer.java:82)
dolphinscheduler-alert_1 | at
org.apache.dolphinscheduler.alert.AlertServer.main(AlertServer.java:89)
dolphinscheduler-alert_1 | Caused by: javax.mail.MessagingException: Could
not convert socket to TLS
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2155)
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:752)
dolphinscheduler-alert_1 | at
javax.mail.Service.connect(Service.java:388)
dolphinscheduler-alert_1 | at
javax.mail.Service.connect(Service.java:246)
dolphinscheduler-alert_1 | at
javax.mail.Service.connect(Service.java:195)
dolphinscheduler-alert_1 | at
javax.mail.Transport.send0(Transport.java:254)
dolphinscheduler-alert_1 | at
javax.mail.Transport.send(Transport.java:124)
dolphinscheduler-alert_1 | at
org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
dolphinscheduler-alert_1 | ... 8 common frames omitted
dolphinscheduler-alert_1 | Caused by: java.io.IOException: Server is not
trusted: smtp.partner.outlook.cn
dolphinscheduler-alert_1 | at
com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:638)
dolphinscheduler-alert_1 | at
com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:553)
dolphinscheduler-alert_1 | at
com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2150)
dolphinscheduler-alert_1 | ... 15 common frames omitted
```
然后换了个思路测试,用相同的 python 代码以上配置,发现可以发送成功,也就是说邮件服务那边设置是没问题的?
下面为 python 代码(不会 java,不好意思)
```
#!/usr/bin/python3
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from email.mime.image import MIMEImage
def main():
# 1. 连接邮箱服务器
# 配置 1,正常发送
# con = smtplib.SMTP('smtp.partner.outlook.cn', 587)
# con.starttls()
# from_email = "[email protected]"
# from_email_pwd = 'xxxx'
# 配置 2,正常发送
con = smtplib.SMTP('smtp.163.com', 25)
con.starttls()
from_email = "[email protected]"
from_email_pwd = 'xxxxx'
con.login(from_email, from_email_pwd)
msg = MIMEMultipart()
subject = Header('找回密码', 'utf-8').encode()
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = '[email protected]'
text = MIMEText('忘记密码需要找回密码', 'plain', 'utf-8')
msg.attach(text)
con.sendmail(from_email, '[email protected]', msg.as_string())
con.quit()
if __name__ == '__main__':
main()
```
**Which version of DolphinScheduler:**
-版本:1.3.6
**Additional context**
env:
kubuntu 21.04 lts
docker
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]