Skip to content

hdx.utilities.email

Utility class to simplify sending emails.

Email Objects

class Email()

[view_source]

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)

Arguments:

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

__enter__

def __enter__() -> "Email"

[view_source]

Return Email object for with statement.

Returns:

None

__exit__

def __exit__(*args: Any) -> None

[view_source]

Close Email object for end of with statement.

Arguments:

  • *args - Not used

Returns:

None

connect

def connect() -> None

[view_source]

Connect to server.

Returns:

None

close

def close() -> None

[view_source]

Close connection to email server.

Returns:

None

get_normalised_emails

@staticmethod
def get_normalised_emails(recipients: Union[str, ListTuple[str]]) -> List[str]

[view_source]

Get list of normalised emails.

Arguments:

  • recipients Union[str, ListTuple[str]] - Email recipient(s)

Returns:

  • List[str] - Normalised emails

send

def send(to: Union[str, ListTuple[str]],
         subject: str,
         text_body: str,
         html_body: Optional[str] = None,
         sender: Optional[str] = None,
         cc: Union[str, ListTuple[str], None] = None,
         bcc: Union[str, ListTuple[str], None] = None,
         **kwargs: Any) -> None

[view_source]

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.

Arguments:

  • to Union[str, ListTuple[str]] - Email recipient(s)
  • subject str - Email subject
  • text_body str - Plain text email body
  • html_body Optional[str] - HTML email body
  • sender Optional[str] - Email sender. Defaults to global sender.
  • cc Union[str, ListTuple[str], None] - Email cc. Defaults to None.
  • bcc Union[str, ListTuple[str], None] - Email bcc. Defaults to None.
  • **kwargs - See below
  • mail_options List - Mail options (see smtplib documentation)
  • rcpt_options List - Recipient options (see smtplib documentation)

Returns:

None