Skip to main content

Simple e-mail composition & decomposition

Project description

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status 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.


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


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

import eletter

TEXT = (
    "Oh my beloved!\n"
    "Wilt thou dine with me on the morrow?\n"
    "We're having hot pockets.\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(,

msg = eletter.compose(
    subject="Meet Me",
    to=[eletter.Address("My Dear", "")],

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(
    "Cela ressemble à un excellent recipie[1] déjeuner.\n"

asparagus_cid = make_msgid()

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

image = eletter.BytesAttachment.from_file(

msg = (text | (html ^ image)).compose(
    subject="Ayons asperges pour le déjeuner",
    from_=eletter.Address("Pepé Le Pew", ""),
        eletter.Address("Penelope Pussycat", ""),
        eletter.Address("Fabrette Pussycat", ""),

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

eletter-0.5.0.tar.gz (65.4 kB view hashes)

Uploaded source

Built Distribution

eletter-0.5.0-py3-none-any.whl (17.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page