smtp_mail_from Always Overwrites from_email in Airflow Email Sending Logic #45983
Labels
area:core
kind:bug
This is a clearly a bug
needs-triage
label for new issues that we didn't triage yet
pending-response
Apache Airflow version
2.10.4
If "Other Airflow 2 version" selected, which one?
2.10.3
What happened?
Description:
The current implementation of email sending in Airflow does not allow the
from_email
parameter to function as intended due to the behavior ofsmtp_mail_from
.The code snippet from send_email_smtp function in airflow/utils/email.py below highlights the issue:
Issue:
smtp_mail_from
is always a string. Even if the configuration inairflow.cfg
leaves it empty,conf.get("smtp", "SMTP_MAIL_FROM")
defaults to an empty string (""
), which is notNone
.from_email
parameter is never used because theif smtp_mail_from is not None
condition is alwaysTrue
.from_email
parameter in various email-related functionalities effectively useless.What you think should happen instead?
Expected Behavior:
The
from_email
parameter should take precedence if explicitly provided, but it currently cannot becausesmtp_mail_from
is neverNone
.Proposed Solution:
Modify the condition to properly handle empty strings and prioritize
from_email
when explicitly set:This change ensures:
smtp_mail_from
is only used when it is explicitly set to a non-empty value.from_email
parameter is respected when provided.How to reproduce
Prerequisites:
Steps to Reproduce:
Clear SMTP Configuration in
airflow.cfg
:In the
airflow.cfg
file, ensure all SMTP-related parameter in the[smtp]
section are left blank or commented out:Restart Airflow:
Restart the Airflow services to apply the changes:
Create an SMTP Connection in the Airflow UI:
smtp_test
SMTP
<SMTP server>
(e.g.,smtp.example.com
)25
[email protected]
Create a DAG with an
EmailOperator
:Use the following sample DAG to send an email:
Trigger the DAG:
test_smtp_from_email
DAG.Expected Behavior:
[email protected]
as theFrom
address whenfrom_email
is explicitly provided.Actual Behavior:
smtp_mail_from
fromairflow.cfg
(likely an empty string or a misconfigured value).from_email
parameter is ignored completely.This demonstrates that the
from_email
parameter is not respected due to the logic prioritizingsmtp_mail_from
, even when it is blank.Operating System
Debian GNU/Linux
Versions of Apache Airflow Providers
No response
Deployment
Docker-Compose
Deployment details
curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.10.3/docker-compose.yaml'
Anything else?
Impact:
This bug impacts all email-sending functionalities, such as email alerts,
EmailOperator
, and any custom email utilities relying on Airflow's email sending methods.Environment:
Let me know if more details or examples are needed!
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: