Brunda10 commented on issue #54690:
URL: https://github.com/apache/airflow/issues/54690#issuecomment-3241901797
I reproduced the SMTP connection issue with Gmail on Airflow 3.x.
The fix was to configure the connection with extra JSON.
Specifically, Gmail on port 587 requires STARTTLS, not SSL.
Without "disable_ssl": true the connection failed (SSL:
WRONG_VERSION_NUMBER), but adding this flag made it work.
Example:
airflow connections add smtp_default \
--conn-type smtp \
--conn-host smtp.gmail.com \
--conn-port 587 \
--conn-login "[email protected]" \
--conn-password "app_password" \
--conn-extra '{"starttls": true, "disable_ssl": true}'
This ensures Airflow uses STARTTLS correctly and avoids SSL handshake errors.
Sample Dag :
```
from airflow import DAG
from airflow.providers.smtp.operators.smtp import EmailOperator
from airflow.providers.standard.operators.python import PythonOperator
from datetime import datetime
def email_success_message():
print("✅ Email sent successfully via Airflow SMTP connection!")
with DAG(
dag_id="test_email_dag",
start_date=datetime(2024, 1, 1),
schedule=None,
catchup=False,
tags=["email", "smtp"],
) as dag:
send_test_email = EmailOperator(
task_id="send_email",
to="[email protected]",
subject="Airflow Email Test",
html_content="<p>Hello! This is a test from Airflow 3.x</p>",
from_email="[email protected]",
)
log_success = PythonOperator(
task_id="log_success",
python_callable=email_success_message,
)
send_test_email >> log_success
```
<img width="1844" height="1099" alt="Image"
src="https://github.com/user-attachments/assets/ea19e6ef-f454-41de-8ddc-316a4b8de5e8"
/>
--
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]