Apache Airflow SMTP Provider

2.4.4 · active · verified Thu Apr 09

The `apache-airflow-providers-smtp` package provides the SmtpHook, enabling Apache Airflow to send emails using SMTP. This is essential for features like email notifications in DAGs via the `EmailOperator`. The current version is 2.4.4, with releases typically synchronized with major Airflow releases or as needed for bug fixes and improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Airflow DAG that uses the `EmailOperator` to send an email. The `apache-airflow-providers-smtp` package must be installed, and an 'smtp_default' connection configured in Airflow for this to function correctly. This provider enables the underlying SMTP communication.

from airflow.operators.email import EmailOperator
from airflow.models.dag import DAG
from datetime import datetime

# NOTE: For this DAG to send emails, an 'smtp_default' connection
# must be configured in Airflow (Admin -> Connections) or via airflow.cfg.
# The apache-airflow-providers-smtp package provides the SmtpHook that EmailOperator uses.

with DAG(
    dag_id='simple_email_notification',
    start_date=datetime(2023, 1, 1),
    schedule_interval=None,
    catchup=False,
    tags=['email_example'],
) as dag:
    send_test_email = EmailOperator(
        task_id='send_test_email',
        to='your_recipient@example.com', # Replace with a valid email address
        subject='Airflow Test Email from SMTP Provider',
        html_content='<h3>Hello from Airflow!</h3><p>This email confirms your SMTP provider is working.</p>',
        conn_id='smtp_default', # This connection ID should be configured
    )

view raw JSON →