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

貢獻者指南