Skip to main content

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status coverage pyversions MIT License

GitHub | PyPI | Documentation | Issues | Changelog

eletter provides functionality for constructing & deconstructing email.message.EmailMessage instances without having to touch the needlessly complicated EmailMessage class itself. A simple function enables composition of e-mails with text and/or HTML bodies plus attachments, and classes are provided for composing more complex multipart e-mails.

Installation

eletter requires Python 3.8 or higher. Just use pip for Python 3 (You have pip, right?) to install eletter and its dependencies:

python3 -m pip install eletter

Examples

Constructing an e-mail with the compose() function:

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],
)

msg can then be sent like any other EmailMessage, say, by using outgoing.

For more complex e-mails, a set of classes is provided. Here is the equivalent of the HTML-with-image e-mail with alternative plain text version from the email examples page in the Python docs:

from email.utils import make_msgid
import eletter

text = eletter.TextBody(
    "Salut!\n"
    "\n"
    "Cela ressemble à un excellent recipie[1] déjeuner.\n"
    "\n"
    "[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718\n"
    "\n"
    "--Pepé\n"
)

asparagus_cid = make_msgid()

html = eletter.HTMLBody(
    "<html>\n"
    "  <head></head>\n"
    "  <body>\n"
    "    <p>Salut!</p>\n"
    "    <p>Cela ressemble à un excellent\n"
    '        <a href="http://www.yummly.com/recipe/Roasted-Asparagus-'
    'Epicurious-203718">\n'
    "            recipie\n"
    "        </a> déjeuner.\n"
    "    </p>\n"
    f'    <img src="cid:{asparagus_cid[1:-1]}" />\n'
    "  </body>\n"
    "</html>\n"
)

image = eletter.BytesAttachment.from_file(
    "roasted-asparagus.jpg",
    inline=True,
    content_id=asparagus_cid,
)

msg = (text | (html ^ image)).compose(
    subject="Ayons asperges pour le déjeuner",
    from_=eletter.Address("Pepé Le Pew", "pepe@example.com"),
    to=[
        eletter.Address("Penelope Pussycat", "penelope@example.com"),
        eletter.Address("Fabrette Pussycat", "fabrette@example.com"),
    ],
)

Release files for eletter 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eletter 0.5.1
File Size Uploaded
eletter-0.5.1.tar.gz 46.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eletter 0.5.1
File Interpreter ABI Platform
eletter-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 64.1 kB

Release files / eletter-0.5.1.tar.gz

Download URL eletter-0.5.1.tar.gz
Size 46.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9d2cccfeda5f98fde5798fa24ac2975c0aaaf158ca3c90a9474432abfe5dec83
BLAKE2b-256 checksum
How to use checksums
1866ecac389903536db0b01be1ea6f35525c4a3472cb09f9bf82f367baa4a4d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / eletter-0.5.1-py3-none-any.whl

Download URL eletter-0.5.1-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60553be28055db300ecaecb08291da867ba94d54c4dc3039b4d9b3a514ca3c27
BLAKE2b-256 checksum
How to use checksums
ea9f2e5e0e4f954cd0152932e5e5468bd51540fe71b622c1c5a4cc7e2b8ce3b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page