apache / apache/airflow

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

Open
#34,554 10 comments 1 reaction 0 assignees View on GitHub
area:core good first issue kind:bug
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 7h
Merged PRs (30d)
484

Description

### 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?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

Contributor guide

Open the contributing guide

Research direction

Start in airflow/utils/email.py and trace the call from EmailOperator, including how AIRFLOW__EMAIL__EMAIL_CONN_ID reaches send_mime_email. Compare the SMTP provider's connection fields with the values currently read from configuration; done means the connection supplies the listed host, port, TLS, sender, timeout, and retry settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.