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

SmtpHook

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]
property smtp_retry_limit: int[source]
property from_email: str | None[source]
property smtp_user: str[source]
property smtp_password: str[source]
property smtp_starttls: bool[source]
property host: str[source]
property port: int[source]
property timeout: int[source]
property use_ssl: bool[source]
conn_name_attr = 'smtp_conn_id'[source]
default_conn_name = 'smtp_default'[source]
conn_type = 'smtp'[source]
hook_name = 'SMTP'[source]
__enter__()[source]
__exit__(exc_type, exc_val, exc_tb)[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

SmtpHook

classmethod get_connection_form_widgets()[source]

Return connection widgets to add to connection form.

test_connection()[source]

Test SMTP connectivity from UI.

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
    )
classmethod get_ui_field_behaviour()[source]

Return custom field behaviour.

Was this entry helpful?