Starttls error when it's disabled in config #39644
Labels
area:core
kind:bug
This is a clearly a bug
needs-triage
label for new issues that we didn't triage yet
Apache Airflow version
2.9.1
If "Other Airflow 2 version" selected, which one?
No response
What happened?
I am trying to use EmailOperator to sent email via SMTP server, but there is error
Traceback
` airflow.ru-central1.internal *** Found local files: *** * /root/airflow/logs/dag_id=email/run_id=manual__2024-05-15T15:41:41.857115+00:00/task_id=email/attempt=1.log [2024-05-15, 22:41:43 +07] {local_task_job_runner.py:120} ▼ Pre task execution logs [2024-05-15, 22:41:43 +07] {taskinstance.py:2076} INFO - Dependencies all met for dep_context=non-requeueable deps ti= [2024-05-15, 22:41:43 +07] {taskinstance.py:2076} INFO - Dependencies all met for dep_context=requeueable deps ti= [2024-05-15, 22:41:43 +07] {taskinstance.py:2306} INFO - Starting attempt 1 of 1 [2024-05-15, 22:41:43 +07] {taskinstance.py:2330} INFO - Executing on 2024-05-15 15:41:41.857115+00:00 [2024-05-15, 22:41:43 +07] {standard_task_runner.py:90} INFO - Running: ['airflow', 'tasks', 'run', 'email', 'email', 'manual__2024-05-15T15:41:41.857115+00:00', '--job-id', '33', '--raw', '--subdir', 'DAGS_FOLDER/test_email.py', '--cfg-path', '/tmp/tmp_576qvon'] [2024-05-15, 22:41:43 +07] {standard_task_runner.py:91} INFO - Job 33: Subtask email [2024-05-15, 22:41:43 +07] {logging_mixin.py:188} WARNING - /usr/local/lib/python3.12/dist-packages/airflow/task/task_runner/standard_task_runner.py:61 DeprecationWarning: This process (pid=65487) is multi-threaded, use of fork() may lead to deadlocks in the child. [2024-05-15, 22:41:43 +07] {standard_task_runner.py:63} INFO - Started process 65493 to run task [2024-05-15, 22:41:43 +07] {task_command.py:426} INFO - Running on host airflow.ru-central1.internal [2024-05-15, 22:41:43 +07] {taskinstance.py:2648} INFO - Exporting env vars: AIRFLOW_CTX_DAG_EMAIL='winmasta@yandex.ru' AIRFLOW_CTX_DAG_OWNER='winmasta' AIRFLOW_CTX_DAG_ID='email' AIRFLOW_CTX_TASK_ID='email' AIRFLOW_CTX_EXECUTION_DATE='2024-05-15T15:41:41.857115+00:00' AIRFLOW_CTX_TRY_NUMBER='1' AIRFLOW_CTX_DAG_RUN_ID='manual__2024-05-15T15:41:41.857115+00:00' [2024-05-15, 22:41:43 +07] {taskinstance.py:430} ▲▲▲ Log group end [2024-05-15, 22:41:43 +07] {logging_mixin.py:188} WARNING - /usr/local/lib/python3.12/dist-packages/airflow/utils/email.py:154 RemovedInAirflow3Warning: Fetching SMTP credentials from configuration variables will be deprecated in a future release. Please set credentials using a connection instead. [2024-05-15, 22:41:43 +07] {email.py:271} INFO - Email alerting: attempt 1 [2024-05-15, 22:41:43 +07] {taskinstance.py:441} ▼ Post task execution logs [2024-05-15, 22:41:43 +07] {taskinstance.py:2905} ERROR - Task failed with exception Traceback (most recent call last): File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 465, in _execute_task result = _execute_callable(context=context, **execute_callable_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 432, in _execute_callable return execute_callable(context=context, **execute_callable_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/models/baseoperator.py", line 400, in wrapper return func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/operators/email.py", line 79, in execute send_email( File "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 80, in send_email return backend( ^^^^^^^^ File "/usr/local/lib/python3.12/dist-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 "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 279, in send_mime_email smtp_conn.starttls() File "/usr/lib/python3.12/smtplib.py", line 794, in starttls raise SMTPResponseException(resp, reply) smtplib.SMTPResponseException: (503, b'5.5.4 Bad sequence of commands. StartTls command has been already sent. 1715787703-hfisA7RwLa60') [2024-05-15, 22:41:43 +07] {taskinstance.py:1206} INFO - Marking task as FAILED. dag_id=email, task_id=email, run_id=manual__2024-05-15T15:41:41.857115+00:00, execution_date=20240515T154141, start_date=20240515T154143, end_date=20240515T154143 [2024-05-15, 22:41:43 +07] {email.py:271} INFO - Email alerting: attempt 1 [2024-05-15, 22:41:43 +07] {email.py:271} INFO - Email alerting: attempt 1 [2024-05-15, 22:41:43 +07] {taskinstance.py:879} ERROR - Failed to send email to: ['winmasta@yandex.ru'] Traceback (most recent call last): File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 2479, in _run_raw_task self._execute_task_with_callbacks(context, test_mode, session=session) File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 2676, in _execute_task_with_callbacks result = self._execute_task(context, task_orig) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 2701, in _execute_task return _execute_task(self, context, task_orig) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 465, in _execute_task result = _execute_callable(context=context, **execute_callable_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 432, in _execute_callable return execute_callable(context=context, **execute_callable_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/models/baseoperator.py", line 400, in wrapper return func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/airflow/operators/email.py", line 79, in execute send_email( File "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 80, in send_email return backend( ^^^^^^^^ File "/usr/local/lib/python3.12/dist-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 "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 279, in send_mime_email smtp_conn.starttls() File "/usr/lib/python3.12/smtplib.py", line 794, in starttls raise SMTPResponseException(resp, reply) smtplib.SMTPResponseException: (503, b'5.5.4 Bad sequence of commands. StartTls command has been already sent. 1715787703-hfisA7RwLa60') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 1063, in _email_alert send_email(task.email, subject, html_content) File "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 80, in send_email return backend( ^^^^^^^^ File "/usr/local/lib/python3.12/dist-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 "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 279, in send_mime_email smtp_conn.starttls() File "/usr/lib/python3.12/smtplib.py", line 794, in starttls raise SMTPResponseException(resp, reply) smtplib.SMTPResponseException: (503, b'5.5.4 Bad sequence of commands. StartTls command has been already sent. 1715787703-hfiB1pU1RW20') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 877, in _handle_failure task_instance.email_alert(error, failure_context["task"]) File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 3163, in email_alert _email_alert(task_instance=self, exception=exception, task=task) File "/usr/local/lib/python3.12/dist-packages/airflow/models/taskinstance.py", line 1065, in _email_alert send_email(task.email, subject, html_content_err) File "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 80, in send_email return backend( ^^^^^^^^ File "/usr/local/lib/python3.12/dist-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 "/usr/local/lib/python3.12/dist-packages/airflow/utils/email.py", line 279, in send_mime_email smtp_conn.starttls() File "/usr/lib/python3.12/smtplib.py", line 794, in starttls raise SMTPResponseException(resp, reply) smtplib.SMTPResponseException: (503, b'5.5.4 Bad sequence of commands. StartTls command has been already sent. 1715787703-hfiTdC0oC0U0') [2024-05-15, 22:41:43 +07] {standard_task_runner.py:110} ERROR - Failed to execute job 33 for task email ((503, b'5.5.4 Bad sequence of commands. StartTls command has been already sent. 1715787703-hfisA7RwLa60'); 65493) [2024-05-15, 22:41:43 +07] {local_task_job_runner.py:240} INFO - Task exited with return code 1 [2024-05-15, 22:41:43 +07] {taskinstance.py:3498} INFO - 0 downstream tasks scheduled from follow-on schedule check [2024-05-15, 22:41:43 +07] {local_task_job_runner.py:222} ▲▲▲ Log group end `but
smtp_starttls
isfalse
inairflow.cfg
# airflow config list
[smtp]
smtp_host = smtp.yandex.ru
smtp_starttls = false
smtp_ssl = true
smtp_user = delta@deltatomsk.ru
smtp_password = ********************
smtp_port = 465
smtp_mail_from = airflow@deltatomsk.ru
smtp_timeout = 30
smtp_retry_limit = 5
What you think should happen instead?
It is supposed to have value from config in
airflow/utils/email.py
278and not to try to use starttls
How to reproduce
Try to use EmailOperator with
smtp_starttls = false
inairflow.cfg
Operating System
Ubuntu 22.04.4 LTS
Versions of Apache Airflow Providers
No response
Deployment
Other
Deployment details
Airflow installed using poetry without virtualenv with python 3.12
requirements.txt
Anything else?
No response
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: