apache-airflow-providers-mailer¶
This provider already carries its own full Sphinx docs tree in its own
repo, under docs/apache-airflow-providers-mailer/. The narrative
content on this page mirrors that; it isn’t a fresh write-up.
Sends email from Airflow tasks via plain SMTP, the Microsoft Graph API, or
SMTP with OAuth2/XOAUTH2 — each backed by its own Airflow connection type so
credentials live in Connections, not DAG code or airflow.cfg.
Connection types¶
For a screenshot walkthrough of creating this connection in the Airflow UI, see Mailer connection.
Connection type |
Display name |
Hook |
|---|---|---|
|
Plain SMTP |
Airflow’s standard SMTP connection — no extra provider needed |
|
Microsoft Graph Email |
|
|
SMTP OAuth Email |
|
Operator¶
EmailOperator(airflow.providers.mailer.operators.email.EmailOperator)Sends an email as a DAG task.
subjectandhtml_contentare Jinja-templated;html_contentalso accepts a path to a.htmlfile, loaded and templated automatically.mailer_conn_idselects which of the three connection types above to send through (defaultsmtp_default). Supportsto/cc/bcc(str or list),files(attachments), and works like any other operator withtrigger_rulefor failure-notification tasks.
Usage¶
from airflow.providers.mailer.operators.email import EmailOperator
notify = EmailOperator(
task_id="notify",
to=["alice@example.com", "bob@example.com"],
cc="manager@example.com",
subject="Pipeline done — {{ ds }}",
html_content="<p>Run {{ run_id }} completed.</p>",
)
on_failure = EmailOperator(
task_id="on_failure_email",
to="oncall@example.com",
subject="[FAILED] ETL pipeline — {{ ds }}",
html_content="<p>Task {{ task_instance.task_id }} failed on {{ ds }}.</p>",
trigger_rule="one_failed",
mailer_conn_id="mailer_graph_default",
)