Microsoft Graph Notifier¶
Microsoft Graph is the recommended way to send mail
from an Office 365 or Outlook cloud mailbox programmatically.
MSGraphNotifier sends an email through the
sendMail endpoint over a
Microsoft Graph API connection.
The permissions the app registration needs and the limit on attachments passed through files are the
same as for the email backend, and are described in Send email using Microsoft Graph. That page also covers routing
the email_on_failure and email_on_retry emails through Microsoft Graph.
Sending a notification¶
from airflow.providers.microsoft.azure.notifications.msgraph import MSGraphNotifier
dag_failure_notification = MSGraphNotifier(
from_email="airflow@example.com",
to="team@example.com",
subject="Dag {{ dag.dag_id }} failed",
html_content="Task {{ ti.task_id }} failed on {{ ds }}",
)
with DAG(
dag_id="mydag",
schedule="@daily",
on_failure_callback=[dag_failure_notification],
):
BashOperator(
task_id="mytask",
bash_command="fail",
on_failure_callback=[
MSGraphNotifier(
from_email="airflow@example.com",
to="team@example.com",
subject="Task {{ ti.task_id }} failed",
html_content="Have a look at the logs of {{ ti.log_url }}",
)
],
)
When from_email is omitted, the [email] from_email configuration option is used instead.