apache/airflow

airflow/utils/email.py def send_mime_email doesn't take all values from connection

开放

#34,554 创建于 2023年9月22日

 (10 条评论) (1 个反应) (0 位负责人)Python (16,781 个派生)batch import
area:coregood first issuekind:bug

仓库指标

星标
 (44,809 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Apache Airflow version

2.7.1

What happened

When defining an SMTP connection only the user and password are taken from the connection. The host, port, starttls, start_ssl, from_email, timeout and retry are all taken from the configuration and not from the connection. Although the smtp provider (https://airflow.apache.org/docs/apache-airflow-providers-smtp/1.0.0/index.html) provides all these fields.

What you think should happen instead

The following lines should be included in airflow/utils/email.py around line 246:

if conn_id is not None:
    try:
        from airflow.hooks.base import BaseHook

        airflow_conn = BaseHook.get_connection(conn_id)
        smtp_user = airflow_conn.login
        smtp_password = airflow_conn.password
        smtp_host = airflow_conn.host
        smtp_port = airflow_conn.port

        extra = json.loads(airflow_conn.extra)

        smtp_starttls = not extra["disable_tls"]
        smtp_timeout = int(extra["timeout"])
        smtp_retry_limit = int(extra["retry_limit"])
        smtp_ssl = not extra["disable_ssl"]

The from_email should be retrieved from the connection earlier in the call stack.

How to reproduce

Install the SMTP provider: pip install apache-airflow-providers-smtp

Create an SMTP connection in the UI Set the AIRFLOW__EMAIL__EMAIL_CONN_ID environment variable to the connection id of the SMTP connection

Use the EmailOperator (from airflow.operators.email import EmailOperator) in a DAG.

Check the values that are used in send_mime_email.

Operating System

Ubuntu

Versions of Apache Airflow Providers

apache-airflow-providers-smtp==1.3.2

Deployment

Docker-Compose

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

贡献者指南