Airflow - 使用 AWS SES 发送电子邮件

Airflow - Send email with AWS SES

尝试使用 AWS Simple Email Service (SES) 从 apache airflow 发送电子邮件,它返回的错误无法帮助我解决问题。我认为这是 SES 中的配置问题,但我不确定要更改什么。

一般信息:

缩写的 DAG 代码:

...
from airflow.operators.email_operator import EmailOperator
...
email_status = EmailOperator(
        task_id="sending_status_email",
        to="myverifiedemail@mydomain.com",
        subject="Test from SES",
        html_content="Trying to send an email from airflow through SES.",
        dag=dag
)
...

airflow.cfg SMTP 设置:

smtp_host = email-smtp.us-east-1.amazonaws.com
smtp_starttls = True
smtp_ssl = False
smtp_user = AWSUSERKEY
smtp_password = PASSWORDFROMAWSSMTP
smtp_port = 587
smtp_mail_from = myverifiedemail@mydomain.com

尝试对 starttls、ssl 和端口设置进行各种更改时收到错误。

ERROR - (554, b'Transaction failed: Unsupported encoding us_ascii.')
ERROR - STARTTLS extension not supported by server.
ERROR - (SSL: WRONG_VERSION_NUMBER) wrong version number (_ssl.c:852)

不确定其他人,但我们今天 运行 遇到了这个错误:

ERROR - (554, b'Transaction failed: Unsupported encoding us_ascii.')

这是 class 的 __init__ 方法中的默认值,该值无效: https://github.com/apache/airflow/blob/1.10.10/airflow/operators/email_operator.py#L63

您可以通过传递一个有效值来修复它,例如“utf-8”:

email_status = EmailOperator(
        mime_charset='utf-8',
        task_id="sending_status_email",
        to="myverifiedemail@mydomain.com",
        subject="Test from SES",
        html_content="Trying to send an email from airflow through SES.",
        dag=dag
)