我按照在线教程在 airflow.cfg 中设置电子邮件 SMTP 服务器,如下所示:
[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 = smtp.gmail.com
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
# smtp_user =
# smtp_password =
smtp_port = 587
smtp_mail_from = myemail@gmail.com
我的 DAG 如下:
from datetime import datetime
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import PythonOperator
from airflow.operators.email_operator import EmailOperator
def print_hello():
return 'Hello world!'
default_args = {
'owner': 'peter',
'start_date':datetime(2018,8,11),
}
dag = DAG('hello_world', description='Simple tutorial DAG',
schedule_interval='* * * * *',
default_args = default_args, catchup=False)
dummy_operator = DummyOperator(task_id='dummy_task', retries=3, dag=dag)
hello_operator = PythonOperator(task_id='hello_task', python_callable=print_hello, dag=dag)
email = EmailOperator(
task_id='send_email',
to='to@gmail.com',
subject='Airflow Alert',
html_content=""" <h3>Email Test</h3> """,
dag=dag
)
email >> dummy_operator >> hello_operator
我假设电子邮件操作员会在其他两个操作员之后运行,然后给我发一封电子邮件。但是电子邮件没有发送给我。非常感谢你的帮助。非常感谢你。
最好
原文由 Peter Cui 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用 Gmail 为 Airflow 电子邮件警报设置 SMTP 服务器:
创建一个电子邮件 ID,您要从中发送有关 DAG 失败的警报,或者如果您想使用 EmailOperator 。编辑
airflow.cfg
文件以编辑邮件服务器的 smtp 详细信息。对于演示,您可以使用任何 gmail 帐户。
为您的 gmail 帐户创建一个谷歌应用程序密码。 [此处说明] 这样做是为了让您不使用原始密码或 2 因素身份验证。
完成后,您将不会再看到该 App 密码代码。但是,您会看到已为其创建应用程序密码的应用程序和设备的列表。
编辑
airflow.cfg
和编辑[smtp]
部分,如下图:将以下参数编辑为相应的值:
YOUR_EMAIL_ADDRESS
= 你的Gmail地址16_DIGIT_APP_PASSWORD
= 上面生成的App密码