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.
Module Contents¶
Classes¶
This hook connects to a mail server by using the smtp protocol. |
- class airflow.providers.smtp.hooks.smtp.SmtpHook(smtp_conn_id=default_conn_name)[source]¶
Bases:
airflow.hooks.base.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.
- property conn: airflow.models.connection.Connection[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, html_content, 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 | Iterable[str]) – Recipient email address or list of addresses.
subject (str) – Email subject.
html_content (str) – Email body in HTML format.
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 | Iterable[str] | None) – Carbon copy recipient email address or list of addresses.
bcc (str | 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 )