MailerGraphHook¶
Send email through the Microsoft Graph API using an Azure AD app-only token.
- class airflow.providers.mailer.hooks.graph.MailerGraphHook(mailer_conn_id: str = 'mailer_graph_default', **kwargs: Any)¶
Basisklassen:
BaseHookSend email through the Microsoft Graph API (
/users/{user_id}/sendMail).Auth is always an Azure AD client-credentials (app-only) flow. Configure:
Client ID – connection
loginClient Secret – connection
passwordtenant_id– extra, Azure AD tenant IDuser_id– extra, UPN or object ID of the mailbox to send as
Optional extras:
from_email(sender override, defaults touser_id) andoauth_scope(defaults tohttps://graph.microsoft.com/.default).- get_conn() Connection¶
Return the resolved Airflow Connection, caching it on the hook instance.
- Returns:
The connection identified by mailer_conn_id.
- Return type:
Connection
- send_email(to: list[str] | str, subject: str, html_content: str, from_email: str | None = None, cc: list[str] | str | None = None, bcc: list[str] | str | None = None, files: list[str] | None = None, **kwargs: Any) None¶
Send an HTML email via
POST /users/{user_id}/sendMail.- Parameters:
to (list[str] | str) – Recipient address(es).
subject (str) – Email subject.
html_content (str) – HTML body.
from_email (str, optional) – Sender override. Defaults to the connection’s
from_emailextra, then user_id.cc (list[str] | str, optional) – Carbon-copy address(es).
bcc (list[str] | str, optional) – Blind carbon-copy address(es).
files (list[str], optional) – Absolute file paths to attach.
**kwargs (Any) – Accepted for interface parity with the other mailer hooks; unused here.
- Veroorzaakt:
ValueError – If the connection is missing the required
user_idextra.RuntimeError – If the Microsoft Graph API returns a non-2xx response.
Example:
from airflow.providers.mailer.hooks.graph import MailerGraphHook MailerGraphHook(mailer_conn_id="my_graph_conn").send_email( to=["ops@example.com"], subject="Deploy finished", html_content="<p>Deploy finished successfully.</p>", )