airflow/utils/email.py def send_mime_email doesn't take all values from connection
#34.554 aperta il 22 set 2023
Metriche repository
- Star
- (44.809 star)
- Metriche merge PR
- (Merge medio 7g 18h) (834 PR mergiate in 30 g)
Descrizione
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
- I agree to follow this project's Code of Conduct