simple_email.Email

class simple_email.Email(from_addr: str, to_addr: Union[str, List], subject: str, body: str, body_type: str = 'plain', cc: Union[str, List] = '', body_encoding: str = 'us-ascii')[source]

Formatted e-mail object to be used with EmailClient.send.

Example

>>> msg = Email(from_addr=email_client.login,
                to_addr="an_email_address@domain.com",
                subject="Sample Subject Line",
                body="Here's the body of the e-mail.",
                cc="another_email_address@domain.com")
>>>
>>> msg.add_attachment(b"Test bytes", "test_file.csv")
>>> msg.add_attachment_from_path(path="/some/path/file.ext")
__init__(from_addr: str, to_addr: Union[str, List], subject: str, body: str, body_type: str = 'plain', cc: Union[str, List] = '', body_encoding: str = 'us-ascii')[source]
Parameters:
  • from_addr – E-mail address the Email should come from.
  • to_addr – E-mail address(es) that will be on the To line of the Email; included in Email recipients.
  • subject – Email’s subject line.
  • body – Text in the body of the e-mail.
  • body_type – Sets the type of text in the body. Defaults to ‘plain’, but can be ‘plain’ or ‘html’.
  • cc – E-mail address(es) that will be on the Cc line of the Email; included in Email recipients.
  • body_encoding – The encoding of the text in the body. Defaults to ‘us-ascii’, but can be ‘utf-8’, etc.

Methods

__init__(from_addr, to_addr, List], subject, …)
param from_addr:
 E-mail address the Email should come from.
add_attachment(data, file_name, maintype, …) Add attachment from bytes object in memory.
add_attachment_from_path(path) Add attachment from path’s contents.