【发布时间】:2019-01-20 14:08:48
【问题描述】:
我按照在线教程在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
我假设电子邮件运算符将在其他两个运算符之后运行,然后向我发送电子邮件。 但是邮件没有发给我。 我真的很感谢你的帮助。非常感谢。
最好的
【问题讨论】:
-
您遇到错误了吗?
-
@mad_ 不,我没有收到任何错误。但是电子邮件没有发送到我的电子邮件地址。我不知道如何实现它。
-
请在问题中添加您的 dag 运行的输出。
-
我假设电子邮件运算符将在其他两个运算符之后运行。实际上,气流上下文中的 't1 >> t2' 意味着 t2 将在 t1 之后发生