airflow.providers.smtp.hooks.smtp¶
Search in emails for a specific attachment and also to download it.
It uses the smtplib library that is already integrated in python 3.
Classes¶
This hook connects to a mail server by using the smtp protocol. |
Functions¶
|
Local fallback for older Airflow cores (≤2.11). |
Module Contents¶
- airflow.providers.smtp.hooks.smtp.build_xoauth2_string(username, token)[source]¶
Local fallback for older Airflow cores (≤2.11).
- class airflow.providers.smtp.hooks.smtp.SmtpHook(smtp_conn_id=default_conn_name, auth_type='basic')[source]¶
Bases:
airflow.providers.smtp.version_compat.BaseHook
This hook connects to a mail server by using the smtp protocol.
Note
Please call this Hook as context manager via with to automatically open and close the connection to the mail server.
- Parameters:
smtp_conn_id (str) – The smtp connection id that contains the information used to authenticate the client.
- smtp_connection: airflow.sdk.Connection | None = None[source]¶
- smtp_client: smtplib.SMTP_SSL | smtplib.SMTP | None = None[source]¶
- get_conn()[source]¶
Login to the smtp server.
Note
Please call this Hook as context manager via with to automatically open and close the connection to the smtp server.
- Returns:
an authorized SmtpHook object.
- Return type:
- classmethod get_connection_form_widgets()[source]¶
Return connection widgets to add to connection form.
- send_email_smtp(*, to, subject=None, html_content=None, from_email=None, files=None, dryrun=False, cc=None, bcc=None, mime_subtype='mixed', mime_charset='utf-8', custom_headers=None, **kwargs)[source]¶
Send an email with html content.
- Parameters:
to (str | collections.abc.Iterable[str]) – Recipient email address or list of addresses.
subject (str | None) – Email subject. If it’s None, the hook will check if there is a path to a subject file provided in the connection, and raises an exception if not.
html_content (str | None) – Email body in HTML format. If it’s None, the hook will check if there is a path to a html content file provided in the connection, and raises an exception if not.
from_email (str | None) – Sender email address. If it’s None, the hook will check if there is an email provided in the connection, and raises an exception if not.
files (list[str] | None) – List of file paths to attach to the email.
dryrun (bool) – If True, the email will not be sent, but all other actions will be performed.
cc (str | collections.abc.Iterable[str] | None) – Carbon copy recipient email address or list of addresses.
bcc (str | collections.abc.Iterable[str] | None) – Blind carbon copy recipient email address or list of addresses.
mime_subtype (str) – MIME subtype of the email.
mime_charset (str) – MIME charset of the email.
custom_headers (dict[str, Any] | None) – Dictionary of custom headers to include in the email.
kwargs – Additional keyword arguments.
>>> send_email_smtp( 'test@example.com', 'foo', '<b>Foo</b> bar', ['/dev/null'], dryrun=True )
- property conn: airflow.sdk.Connection[source]¶