Send email using Microsoft Graph¶
Airflow can be configured to send e-mail from an Office 365 or Outlook cloud mailbox using
Microsoft Graph as the
email_backend, so that task callback emails (success, failure, retry) go out through Graph instead
of SMTP. See Email Configuration for the general Airflow email configuration this
page builds on.
Note
If you instead want to send an email from a task callback or a deadline alert, use the MSGraphNotifier documented in Microsoft Graph Notifier.
Follow the steps below to enable it:
Install the
microsoft-azureprovider as part of your Airflow installation:pip install 'apache-airflow[microsoft-azure]'
Update the
[email]section inairflow.cfg:[email] email_backend = airflow.providers.microsoft.azure.hooks.msgraph.send_email email_conn_id = msgraph_default from_email = From email <email@example.com>
Equivalent environment variables look like:
AIRFLOW__EMAIL__EMAIL_BACKEND=airflow.providers.microsoft.azure.hooks.msgraph.send_email AIRFLOW__EMAIL__EMAIL_CONN_ID=msgraph_default AIRFLOW__EMAIL__FROM_EMAIL=email@example.com
from_emailis required and selects the mailbox the message is sent from.Create a connection called
msgraph_default, or choose a custom connection name and set it inemail_conn_id, of typeMicrosoft Graph API. See Microsoft Graph API Connection for how to configure it.
The app registration behind the connection needs the Mail.Send permission. When application
permissions are used, an administrator has to grant the application access to the sending mailbox, for
example by scoping it with an
application access policy.
Attachments are sent inline in the request body, which Microsoft Graph limits to 4 MB in total.
Attachments adding up to more than 3 MB are rejected with a ValueError, and have to be uploaded to
a draft message with an upload session instead.