airflow.providers.smtp.utils.emailer

Send email using the [email] and [smtp] Airflow configuration sections.

Attributes

log

Functions

send_email(to, subject, html_content[, files, dryrun, ...])

Send an email using the backend specified in the EMAIL_BACKEND configuration option.

send_email_smtp(to, subject, html_content[, files, ...])

Send an email with html content.

build_mime_message(mail_from, to, subject, html_content)

Build a MIME message that can be used to send an email and returns a full list of recipients.

send_mime_email(e_from, e_to, mime_msg[, conn_id, dryrun])

Send a MIME email.

get_email_address_list(addresses)

Return a list of email addresses from the provided input.

Module Contents

airflow.providers.smtp.utils.emailer.log[source]
airflow.providers.smtp.utils.emailer.send_email(to, subject, html_content, files=None, dryrun=False, cc=None, bcc=None, mime_subtype='mixed', mime_charset='utf-8', conn_id=None, custom_headers=None, **kwargs)[source]

Send an email using the backend specified in the EMAIL_BACKEND configuration option.

Parameters:
  • to (list[str] | collections.abc.Iterable[str]) – A list or iterable of email addresses to send the email to.

  • subject (str) – The subject of the email.

  • html_content (str) – The content of the email in HTML format.

  • files (list[str] | None) – A list of paths to files to attach to the email.

  • dryrun (bool) – If True, the email will not actually be sent. Default: False.

  • cc (str | collections.abc.Iterable[str] | None) – A string or iterable of strings containing email addresses to send a copy of the email to.

  • bcc (str | collections.abc.Iterable[str] | None) – A string or iterable of strings containing email addresses to send a blind carbon copy of the email to.

  • mime_subtype (str) – The subtype of the MIME message. Default: “mixed”.

  • mime_charset (str) – The charset of the email. Default: “utf-8”.

  • conn_id (str | None) – The connection ID to use for the backend. If not provided, the default connection specified in the EMAIL_CONN_ID configuration option will be used.

  • custom_headers (dict[str, Any] | None) – A dictionary of additional headers to add to the MIME message. No validations are run on these values, and they should be able to be encoded.

  • kwargs – Additional keyword arguments to pass to the backend.

airflow.providers.smtp.utils.emailer.send_email_smtp(to, subject, html_content, files=None, dryrun=False, cc=None, bcc=None, mime_subtype='mixed', mime_charset='utf-8', conn_id='smtp_default', from_email=None, 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) – Email subject.

  • html_content (str) – Email body in HTML format.

  • 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.

  • conn_id (str) – Connection ID of the SMTP server.

  • from_email (str | None) – Sender email address.

  • custom_headers (dict[str, Any] | None) – Dictionary of custom headers to include in the email.

  • kwargs – Additional keyword arguments.

>>> send_email("test@example.com", "foo", "<b>Foo</b> bar", ["/dev/null"], dryrun=True)
airflow.providers.smtp.utils.emailer.build_mime_message(mail_from, to, subject, html_content, files=None, cc=None, bcc=None, mime_subtype='mixed', mime_charset='utf-8', custom_headers=None)[source]

Build a MIME message that can be used to send an email and returns a full list of recipients.

Parameters:
  • mail_from (str | None) – Email address to set as the email’s “From” field.

  • to (str | collections.abc.Iterable[str]) – A string or iterable of strings containing email addresses to set as the email’s “To” field.

  • subject (str) – The subject of the email.

  • html_content (str) – The content of the email in HTML format.

  • files (list[str] | None) – A list of paths to files to be attached to the email.

  • cc (str | collections.abc.Iterable[str] | None) – A string or iterable of strings containing email addresses to set as the email’s “CC” field.

  • bcc (str | collections.abc.Iterable[str] | None) – A string or iterable of strings containing email addresses to set as the email’s “BCC” field.

  • mime_subtype (str) – The subtype of the MIME message. Default: “mixed”.

  • mime_charset (str) – The charset of the email. Default: “utf-8”.

  • custom_headers (dict[str, Any] | None) – Additional headers to add to the MIME message. No validations are run on these values, and they should be able to be encoded.

Returns:

A tuple containing the email as a MIMEMultipart object and a list of recipient email addresses.

Return type:

tuple[email.mime.multipart.MIMEMultipart, list[str]]

airflow.providers.smtp.utils.emailer.send_mime_email(e_from, e_to, mime_msg, conn_id='smtp_default', dryrun=False)[source]

Send a MIME email.

Parameters:
  • e_from (str) – The email address of the sender.

  • e_to (str | list[str]) – The email address or a list of email addresses of the recipient(s).

  • mime_msg (email.mime.multipart.MIMEMultipart) – The MIME message to send.

  • conn_id (str) – The ID of the SMTP connection to use.

  • dryrun (bool) – If True, the email will not be sent, but a log message will be generated.

airflow.providers.smtp.utils.emailer.get_email_address_list(addresses)[source]

Return a list of email addresses from the provided input.

Parameters:

addresses (str | collections.abc.Iterable[str]) – A string or iterable of strings containing email addresses.

Returns:

A list of email addresses.

Raises:

TypeError – If the input is not a string or iterable of strings.

Return type:

list[str]

Was this entry helpful?