【问题标题】:On Airflow, getting Connection refused while connecting to SMTP host在 Airflow 上,连接到 SMTP 主机时连接被拒绝
【发布时间】:2021-12-16 21:04:36
【问题描述】:

按照下面文章中解释的类似内容,通过 Airflow 中的 SMTP 服务器发送电子邮件: https://towardsdatascience.com/automating-emails-in-apache-airflow-a-how-to-guide-1d2330a29d1e

我没有像在我们的生产环境中那样使用默认的airflow.cfg 来配置smtp 主机,我们无法控制它。 但在产品中,似乎 Airflow 无法连接到 SMTP 主机,而我可以在本地运行相同的代码并获取电子邮件。 错误如下:

Error description

我们还通过 prod 服务器上的独立 python 脚本检查,我们能够访问 SMTP 主机,所以这不是主机问题,而是 Airflow。

对此有何建议?

【问题讨论】:

    标签: python smtp airflow smtplib


    【解决方案1】:

    嗯,我们发现这是从生产机器连接到远程 SMTP 服务器的问题,可能是由于客户端和服务器之间的防火墙。 我们通过在这些 prod 框中运行 python 脚本来确认它,并且在连接时它在以下行失败:

    server = smtplib.SMTP(smtp_server) 
    
    server.sendmail(sender_email, receiver_email, message.as_string())
    

    错误: ConnectionRefusedError: [Errno 111] 连接被拒绝

    为之前的困惑道歉。

    之前我们通过 sendmail unix 命令进行了尝试,它成功了,所以造成了混乱:

    sendmail email_address -s smtp_server
    
    Subject: Test mail from prod_env
    
    Hello, email received
    

    所以这不是 Airflow 的问题,只是从 prod 服务器连接到 smtp 服务器。 谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 2020-03-14
      • 2012-06-28
      相关资源
      最近更新 更多