Simple e-mail composition
Project description
eletter provides a basic function for constructing an email.message.EmailMessage instance without having to touch the needlessly complicated EmailMessage class itself. E-mails with text bodies and/or HTML bodies plus attachments are supported. Support for more complex e-mails is planned for later.
Installation
eletter requires Python 3.6 or higher. Just use pip for Python 3 (You have pip, right?) to install eletter and its dependencies:
python3 -m pip install eletter
Example
import eletter
TEXT = (
"Oh my beloved!\n"
"\n"
"Wilt thou dine with me on the morrow?\n"
"\n"
"We're having hot pockets.\n"
"\n"
"Love, Me\n"
)
HTML = (
"<p>Oh my beloved!</p>\n"
"<p>Wilt thou dine with me on the morrow?</p>\n"
"<p>We're having <strong>hot pockets</strong>.<p>\n"
"<p><em>Love</em>, Me</p>\n"
)
with open("hot-pocket.png", "rb") as fp:
picture = eletter.BytesAttachment(
content=fp.read(),
filename="enticement.png",
content_type="image/png",
)
msg = eletter.compose(
subject="Meet Me",
from_="me@here.qq",
to=[eletter.Address("My Dear", "my.beloved@love.love")],
text=TEXT,
html=HTML,
attachments=[picture],
)
# Now you can send `msg` like any other EmailMessage, say, by using
# outgoing <https://github/jwodder/outgoing>.
API
eletter.compose(
subject: str,
from_: Union[str, Address],
to: Iterable[Union[str, Address]],
text: Optional[str] = None,
html: Optional[str] = None,
cc: Optional[Iterable[Union[str, Address]]] = None,
bcc: Optional[Iterable[Union[str, Address]]] = None,
reply_to: Optional[Union[str, Address]] = None,
sender: Optional[Union[str, Address]] = None,
date: Optional[datetime.datetime] = None,
attachments: Optional[Iterable[Attachment]] = None,
headers: Optional[Mapping[str, Union[str, Iterable[str]]]] = None,
) -> email.message.EmailMessage
Construct an EmailMessage instance from a subject, “From:” address, “To:” value, and a plain text and/or HTML body, optionally accompanied by attachments and other headers.
Addresses are specified as either "address@domain.com" strings or as eletter.Address("Display Name", "address@domain.com") objects.
Arguments:
- subjectstring (required)
The e-mail’s “Subject:” line
- from_address (required)
The e-mail’s “From:” line. Note that this argument is spelled with an underscore, as “from” is a keyword in Python.
- toiterable of addresses (required)
The e-mail’s “To:” line
- textstring
The contents of a text/plain body for the e-mail. At least one of text and html must be specified.
- htmlstring
The contents of a text/html body for the e-mail. At least one of text and html must be specified.
- cciterable of addresses (optional)
The e-mail’s “CC:” line
- bcciterable of addresses (optional)
The e-mail’s “BCC:” line
- reply_toaddress (optional)
The e-mail’s “Reply-To:” line
- senderaddress (optional)
The e-mail’s “Sender:” line
- datedatetime (optional)
The e-mail’s “Date:” line
- attachmentsiterable of attachments (optional)
A collection of attachments (see below) to append to the e-mail
- headersmapping from header names to strings or iterables of strings (optional)
A collection of additional headers to add to the e-mail. A header value may be either a single string or an iterable of strings to add multiple headers with the same name.
Attachment Objects
eletter has two concrete attachment classes, TextAttachment and BytesAttachment:
eletter.BytesAttachment(
content: bytes,
filename: str,
content_type: str = "application/octet-stream",
inline: bool = False,
)
Representation of a binary attachment.
eletter.TextAttachment(
content: str,
filename: str,
content_type: str = "text/plain",
inline: bool = False,
)
Representation of a text attachment. The content type must have a maintype of “text”.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file eletter-0.1.0.tar.gz
.
File metadata
- Download URL: eletter-0.1.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c439a2d610266c524d98660175550491eb383fee3cd9aeba69b095a2257c79f7 |
|
MD5 | 4dd9ff1a7d38884ccdf447a64968c283 |
|
BLAKE2b-256 | aa965b0a63b0d1fe7f6b129ab435de8bbce3535ea30bae05d9cafeb41f831542 |
Provenance
File details
Details for the file eletter-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: eletter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd64de6e055a62fe2749095ee1bfad6441c0f75d6f2c2bf446340fbc564d7301 |
|
MD5 | 804fa3fcf4e9dcfafb700c77f197a137 |
|
BLAKE2b-256 | 8447532e457592b2b7ea68e74769707f5116f21d7669fff9b7d514f728b77f1b |