Skip to content

hdx.utilities.email

module hdx.utilities.email

Utility class to simplify sending emails.

Classes

class EmailConfigurationError()

Bases : Exception

class EmailSendError()

Bases : Exception

class Email(**kwargs: Any)

Emailer utility. Parameters in dictionary or file (eg. yaml below):

| connection_type: "ssl" ("ssl" for smtp ssl or "lmtp", otherwise basic smtp is assumed) | host: "localhost" | port: 123 | local_hostname: "mycomputer.fqdn.com" | timeout: 3 | username: "user" | password: "pass" | sender: "a@b.com" (if not supplied username is used as sender)

Parameters

  • **kwargs : Any — See below

  • email_config_dict : dict — HDX configuration dictionary OR

  • email_config_json : str — Path to JSON HDX configuration OR

  • email_config_yaml : str — Path to YAML HDX configuration. Defaults to ~/hdx_email_configuration.yaml.

Methods

  • connect — Connect to server.

  • close — Close connection to email server.

  • get_normalised_email — Get normalised email.

  • get_normalised_emails — Get list of normalised emails.

  • send — Send email. to, cc and bcc take either a string email address or a list of string email addresses. cc and bcc default to None.

method Email.connect() → None

Connect to server.

Returns

  • None — None

method Email.close() → None

Close connection to email server.

Returns

  • None — None

staticmethod Email.get_normalised_email(email: str, check_deliverability: bool = False) → str

Get normalised email.

Parameters

  • email : str — Email address to normalise

Returns

  • str — Normalised email

Raises

classmethod Email.get_normalised_emails(emails: str | Sequence[str]) → list[str]

Get list of normalised emails.

Parameters

  • emails : str | Sequence[str] — Email address or addresses

Returns

  • list[str] — Normalised emails

method Email.send(to: str | Sequence[str], subject: str, text_body: str, html_body: str | None = None, sender: str | None = None, cc: str | Sequence[str] | None = None, bcc: str | Sequence[str] | None = None, **kwargs: Any) → None

Send email. to, cc and bcc take either a string email address or a list of string email addresses. cc and bcc default to None.

Parameters

  • to : str | Sequence[str] — Email recipient(s)

  • subject : str — Email subject

  • text_body : str — Plain text email body

  • html_body : str | None — HTML email body

  • sender : str | None — Email sender. Defaults to global sender.

  • cc : str | Sequence[str] | None — Email cc. Defaults to None.

  • bcc : str | Sequence[str] | None — Email bcc. Defaults to None.

  • **kwargs : Any — See below

  • mail_options : list — Mail options (see smtplib documentation)

  • rcpt_options : list — Recipient options (see smtplib documentation)

Returns

  • None — None