【问题标题】:Emails with Airflow带有气流的电子邮件
【发布时间】:2019-02-05 07:31:01
【问题描述】:

我是否必须进行任何其他设置才能让 apache-airflow 向我发送有关任务失败的电子邮件。我的配置文件中有以下内容(未更改默认值):

[email]
email_backend = airflow.utils.email.send_email_smtp


[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = localhost
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
# smtp_user = airflow
# smtp_password = airflow
smtp_port = 25
smtp_mail_from = airflow@example.com

在我的任务中,我有

'email': ['my.email@domain.co.uk'],
'email_on_failure': True,

但是当任务失败时它不会给我发送电子邮件。

我已经看到了这个问题:How do I setup Airflow's email configuration to send an email on errors?,但我真的不明白要从中采取什么行动。我只是在寻找气流发送电子邮件之前需要做什么的基础知识。我是否必须配置我自己的 smtp 服务器,还是应该直接使用?

我在 CentOS 上运行 apache-airflow 1.9.0

【问题讨论】:

    标签: email smtp airflow


    【解决方案1】:

    如果您更喜欢使用 Sendgrid,气流贡献中提供了一个 Sendgrid 子包 https://github.com/apache/airflow/blob/master/airflow/contrib/utils/sendgrid.py

    然后按照链接中提到的说明进行操作。

        0. include sendgrid subpackage as part of your Airflow installation, e.g.,
        pip install apache-airflow[sendgrid] 
    
        1. update [email] backend in airflow.cfg, i.e.,
        [email]
        email_backend = airflow.contrib.utils.sendgrid.send_email
    
        2. configure Sendgrid specific environment variables at all Airflow instances:
        SENDGRID_MAIL_FROM={your-mail-from}
        SENDGRID_API_KEY={your-sendgrid-api-key}.
    

    【讨论】:

    • 电子邮件后端看起来将在 Airflow 2.0 或附近更新为email_backend=airflow.providers.sendgrid.utils.emailer,如here所示
    【解决方案2】:

    您需要自己的 SMTP 服务。我们在内部使用 Mailgun 和 Sendgrid,效果很好。您只需要使用您的凭据更改 .cfg 中的这些行,重新启动气流,就可以开始了!

    【讨论】:

    • 谢谢,您对设置最简单(免费?)的 SMTP 服务有什么看法吗?我现在来看看 Mailgun 和 Sendgrid。我需要两者吗?
    • 我相信 Mailgun 可以免费为您提供 10K 封电子邮件。任何一个都应该工作 - 你应该只需要一个。
    • 我已经在 Mailgun 上设置了一个帐户,并且我的终端中使用了他们网站上的 swaks example。除了填写我的用户名和密码之外,我还需要做些什么来让气流与气流一起工作吗?我必须将气流配置文件中的smtp_host 更改为smtp.mailgun.org吗?
    • 是的,我认为您必须这样做 - 以及其他凭据。不应该是除此之外的任何东西
    猜你喜欢
    • 2021-09-17
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    相关资源
    最近更新 更多