andreh998 opened a new issue, #55953:
URL: https://github.com/apache/airflow/issues/55953
### Apache Airflow version
3.0.6
### If "Other Airflow 2 version" selected, which one?
3.0.6 (also reproduced in 3.1.0rc1)
### What happened?
I am configuring Airflow to send emails when a task fails. When configuring
SMTP email settings via [smtp] section in airflow.cfg or via environment
variables (AIRFLOW__SMTP__SMTP_*), Airflow fails to authenticate against Gmail
SMTP. I even created a test DAG that fails on purpose just to trigger the
email, and it consistently shows the same issue.
My airflow.cfg:
> [email]
> email_backend = airflow.utils.email.send_email_smtp
> subject_template = /opt/airflow/config/my_subject_template_file.txt
> html_content_template =
/opt/airflow/config/my_html_content_template_file.html
> from_email = **@****.com.br
>
> [smtp]
> smtp_host = smtp.gmail.com
> smtp_starttls = True
> smtp_ssl = False
> smtp_port = 587
> smtp_user = test@****.com.br
> smtp_mail_from = ***@****.com.br
> # smtp_password = password_here # i try put the password here to
my docker-compose.yaml
> AIRFLOW__SMTP__SMTP_PASSWORD: 'password_here' # password SMTP
I created a test DAG that fails on purpose just to send the email:
```
import pendulum
from airflow.decorators import task, dag
@dag(
dag_id="email_test_dag",
start_date=pendulum.datetime(2025, 9, 1, tz="UTC"),
schedule=None,
catchup=False,
tags=["test", "email"],
default_args={
'owner': 'airflow',
'email_on_failure': True,
'email_on_retry': False,
'email': ['andre.hoffmann@****.com.br',],
}
)
def email_test_dag():
@task
def raise_error_and_send_email():
raise ValueError("Test email")
raise_error_and_send_email()
email_test_dag_instance = email_test_dag()
```
I can retrieve the information from both airflow.cfg and the environment
using the commands below, in both the worker and the scheduler containers.:
```
airflow@3ff76e0d829c:/opt/airflow$ airflow config get-value smtp smtp_user
****@*****.com.br
airflow@3ff76e0d829c:/opt/airflow$ airflow config get-value smtp
smtp_password
password_here
```
But after running the DAG I get the following errors:
```
Log message source details:
sources=["/opt/airflow/logs/dag_id=email_test_dag/run_id=manual__2025-09-22T12:13:57.617716+00:00/task_id=raise_error_and_send_email/attempt=1.log"]
[2025-09-22, 09:14:08] INFO - DAG bundles loaded: dags-folder:
source="airflow.dag_processing.bundles.manager.DagBundlesManager"
[2025-09-22, 09:14:08] INFO - Filling up the DagBag from
/opt/airflow/dags/email_test_dag.py: source="airflow.models.dagbag.DagBag"
[2025-09-22, 09:14:08] ERROR - Task failed with exception: source="task"
ValueError: Teste de falha de e-mail do Airflow!
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 920 in run
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 1215 in _execute_task
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py",
line 397 in wrapper
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/decorator.py",
line 251 in execute
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py",
line 397 in wrapper
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py",
line 216 in execute
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py",
line 239 in execute_callable
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/callback_runner.py",
line 81 in run
File "/opt/airflow/dags/email_test_dag.py", line 27 in
raise_error_and_send_email
[2025-09-22, 09:14:08] WARNING -
/home/airflow/.local/lib/python3.12/site-packages/airflow/models/connection.py:471:
DeprecationWarning: Using Connection.get_connection_from_secrets from
`airflow.models` is deprecated.Please use `get` on Connection from
sdk(`airflow.sdk.Connection`) instead
warnings.warn(
: source="py.warnings"
[2025-09-22, 09:14:08] INFO - Email alerting: attempt 1:
source="airflow.utils.email"
[2025-09-22, 09:14:09] INFO - Sent an alert email to
['andre.hoffmann@****.com.br', 'augusto.hagemeier@****.com.br']:
source="airflow.utils.email"
[2025-09-22, 09:14:10] INFO - Email alerting: attempt 1:
source="airflow.utils.email"
[2025-09-22, 09:14:10] INFO - Sent an alert email to
['andre.hoffmann@****.com.br', 'augusto.hagemeier@****.com.br']:
source="airflow.utils.email"
[2025-09-22, 09:14:11] ERROR - Top level error: source="task"
SMTPSenderRefused: (530, b'5.7.0 Authentication Required. For more
information, go to\n5.7.0
https://support.google.com/accounts/troubleshooter/2402620.
d9443c01a7336-2698030ee20sm131927125ad.109 - gsmtp', '***@****.com.br')
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 1353 in main
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 1330 in finalize
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 1165 in _send_task_error_email
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 79 in send_email
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 154 in send_email_smtp
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 273 in send_mime_email
File "/usr/local/lib/python3.12/smtplib.py", line 876 in sendmail
SMTPSenderRefused: (530, b'5.7.0 Authentication Required. For more
information, go to\n5.7.0
https://support.google.com/accounts/troubleshooter/2402620.
d9443c01a7336-269802de979sm132468545ad.69 - gsmtp', '***@****.com.br')
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 1163 in _send_task_error_email
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 79 in send_email
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 154 in send_email_smtp
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 273 in send_mime_email
File "/usr/local/lib/python3.12/smtplib.py", line 876 in sendmail
[2025-09-22, 09:14:11] WARNING - Process exited abnormally: exit_code=1:
source="task"
```
tried switching between ports 587 and 465, between SSL and TLS, and I also
tried adding all the configurations from airflow.cfg into docker-compose.yaml
as environment variables, but the error persisted.
Even when testing via Python and importing send_email_smtp, I was not able
to succeed:
```
>>> from airflow.utils.email import send_email_smtp
>>> send_email_smtp( ... to="andre.hoffmann@****.com.br", subject="Test SMTP
Airflow", html_content="Test")
[2025-09-22T11:52:58.491+0000] {email.py:261} INFO - Email alerting: attempt
1
[2025-09-22T11:52:59.304+0000] {email.py:272} INFO - Sent an alert email to
['andre.hoffmann@****.com.br']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 154, in send_email_smtp send_mime_email(e_from=mail_from, e_to=recipients,
mime_msg=msg, conn_id=conn_id, dryrun=dryrun)
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/email.py",
line 273, in send_mime_email smtp_conn.sendmail(e_from, e_to,
mime_msg.as_string()) File "/usr/local/lib/python3.12/smtplib.py", line 876, in
sendmail raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. For more
information, go to\n5.7.0
https://support.google.com/accounts/troubleshooter/2402620.
d9443c01a7336-26980053201sm131546055ad.17 - gsmtp', '***@****.com.br')
>>>
```
Only after defining a default SMTP connection in the environment variables,
it worked:
> AIRFLOW_CONN_SMTP_DEFAULT:
"smtp://***%40****.com.br:[email protected]:587?secure=starttls"
Airflow task test:
```
Log message source details:
sources=["/opt/airflow/logs/dag_id=email_test_dag/run_id=manual__2025-09-22T13:09:36.683154+00:00/task_id=raise_error_and_send_email/attempt=1.log"]
::group::Log message source details:
sources=["/opt/airflow/logs/dag_id=email_test_dag/run_id=manual__2025-09-22T13:09:36.683154+00:00/task_id=raise_error_and_send_email/attempt=1.log"]
[2025-09-22, 10:09:51] INFO - DAG bundles loaded: dags-folder:
source="airflow.dag_processing.bundles.manager.DagBundlesManager"
[2025-09-22, 10:09:51] INFO - Filling up the DagBag from
/opt/airflow/dags/email_test_dag.py: source="airflow.models.dagbag.DagBag"
[2025-09-22, 10:09:51] ERROR - Task failed with exception: source="task"
ValueError: Teste de falha de e-mail do Airflow!
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 920 in run
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py",
line 1215 in _execute_task
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py",
line 397 in wrapper
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/decorator.py",
line 251 in execute
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py",
line 397 in wrapper
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py",
line 216 in execute
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py",
line 239 in execute_callable
File
"/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/callback_runner.py",
line 81 in run
File "/opt/airflow/dags/email_test_dag.py", line 27 in
raise_error_and_send_email
[2025-09-22, 10:09:52] WARNING -
/home/airflow/.local/lib/python3.12/site-packages/airflow/models/connection.py:471:
DeprecationWarning: Using Connection.get_connection_from_secrets from
`airflow.models` is deprecated.Please use `get` on Connection from
sdk(`airflow.sdk.Connection`) instead
warnings.warn(
: source="py.warnings"
[2025-09-22, 10:09:52] WARNING - empty cryptography key - values will not be
stored encrypted.: source="airflow.models.crypto"
[2025-09-22, 10:09:52] INFO - Connection Retrieved 'smtp_default':
source="airflow.hooks.base"
[2025-09-22, 10:09:52] INFO - Email alerting: attempt 1:
source="airflow.utils.email"
[2025-09-22, 10:09:53] INFO - Sent an alert email to
['andre.hoffmann@****.com.br']: source="airflow.utils.email"
```
### What you think should happen instead?
It should work just by setting the environment variables or the airflow.cfg.
### How to reproduce
By filling in the SMTP information in the airflow.cfg and/or in the .env
file and running a task that fails.
### Operating System
apache/airflow:3.1.0rc1
### Versions of Apache Airflow Providers
_No response_
### 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
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]