simple_email’s documentation¶
simple_email is an easy API for sending e-mails based on the Python smtplib and email standard libraries.
Installation¶
pip install simple_email
Quickstart¶
Easy API for sending e-mails based on smtplib and email.
Example
>>> from simple_email import Email, EmailClient
>>>
>>> # Note: EMAIL and EMAIL_AUTH refer to hypothetical environment variables
>>> # NEVER hard-code your auth in your code!
>>> email_client = EmailClient(login=EMAIL, password=EMAIL_AUTH,
host='smtp.office365.com', port=587)
>>>
>>> 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")
>>>
>>> email_client.send(msg)
Classes¶
Email (from_addr, to_addr, List], subject, …) |
Formatted e-mail object to be used with EmailClient.send. |
EmailClient (login, password, host, port) |
Email client that will be used to send and receive e-mails. |
Functions¶
parse_email_addr (email) |
Strips surrounding angle brackets from an e-mail address. |
path_to_bytes (path) |
Helper function to get a bytes object from the contents of a file on disk. |
path_to_attachment_components |
Helper function to get a file’s bytes and metadata for use with Email.add_attachment. |