hdx.utilities.email
Utility class to simplify sending emails.
Email Objects
class Email()
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 belowemail_config_dict
dict - HDX configuration dictionary ORemail_config_json
str - Path to JSON HDX configuration ORemail_config_yaml
str - Path to YAML HDX configuration. Defaults to ~/hdx_email_configuration.yaml.
__enter__
def __enter__() -> "Email"
Return Email object for with statement.
Returns:
None
__exit__
def __exit__(*args: Any) -> None
Close Email object for end of with statement.
Arguments:
*args
- Not used
Returns:
None
connect
def connect() -> None
Connect to server.
Returns:
None
close
def close() -> None
Close connection to email server.
Returns:
None
get_normalised_emails
@staticmethod
def get_normalised_emails(recipients: Union[str, ListTuple[str]]) -> List[str]
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
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 subjecttext_body
str - Plain text email bodyhtml_body
Optional[str] - HTML email bodysender
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 belowmail_options
List - Mail options (see smtplib documentation)rcpt_options
List - Recipient options (see smtplib documentation)
Returns:
None