eletter


Nameeletter JSON
Version 0.5.1 PyPI version JSON
download
home_pageNone
SummarySimple e-mail composition & decomposition
upload_time2024-12-01 12:38:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords emailmessage e-mail email message
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |repostatus| |ci-status| |coverage| |pyversions| |license|

.. |repostatus| image:: https://www.repostatus.org/badges/latest/active.svg
    :target: https://www.repostatus.org/#active
    :alt: Project Status: Active — The project has reached a stable, usable
          state and is being actively developed.

.. |ci-status| image:: https://github.com/jwodder/eletter/actions/workflows/test.yml/badge.svg
    :target: https://github.com/jwodder/eletter/actions/workflows/test.yml
    :alt: CI Status

.. |coverage| image:: https://codecov.io/gh/jwodder/eletter/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/jwodder/eletter

.. |pyversions| image:: https://img.shields.io/pypi/pyversions/eletter.svg
    :target: https://pypi.org/project/eletter/

.. |license| image:: https://img.shields.io/github/license/jwodder/eletter.svg
    :target: https://opensource.org/licenses/MIT
    :alt: MIT License

`GitHub <https://github.com/jwodder/eletter>`_
| `PyPI <https://pypi.org/project/eletter/>`_
| `Documentation <https://eletter.readthedocs.io>`_
| `Issues <https://github.com/jwodder/eletter/issues>`_
| `Changelog <https://github.com/jwodder/eletter/blob/master/CHANGELOG.md>`_

``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
<https://pip.pypa.io>`_ 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:

.. code:: python

    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_.

.. _outgoing: https://github.com/jwodder/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:

__ https://docs.python.org/3/library/email.examples.html

.. code:: python

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "eletter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "EmailMessage, e-mail, email, message",
    "author": null,
    "author_email": "John Thorvald Wodder II <eletter@varonathe.org>",
    "download_url": "https://files.pythonhosted.org/packages/18/66/ecac389903536db0b01be1ea6f35525c4a3472cb09f9bf82f367baa4a4d0/eletter-0.5.1.tar.gz",
    "platform": null,
    "description": "|repostatus| |ci-status| |coverage| |pyversions| |license|\n\n.. |repostatus| image:: https://www.repostatus.org/badges/latest/active.svg\n    :target: https://www.repostatus.org/#active\n    :alt: Project Status: Active \u2014 The project has reached a stable, usable\n          state and is being actively developed.\n\n.. |ci-status| image:: https://github.com/jwodder/eletter/actions/workflows/test.yml/badge.svg\n    :target: https://github.com/jwodder/eletter/actions/workflows/test.yml\n    :alt: CI Status\n\n.. |coverage| image:: https://codecov.io/gh/jwodder/eletter/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/jwodder/eletter\n\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/eletter.svg\n    :target: https://pypi.org/project/eletter/\n\n.. |license| image:: https://img.shields.io/github/license/jwodder/eletter.svg\n    :target: https://opensource.org/licenses/MIT\n    :alt: MIT License\n\n`GitHub <https://github.com/jwodder/eletter>`_\n| `PyPI <https://pypi.org/project/eletter/>`_\n| `Documentation <https://eletter.readthedocs.io>`_\n| `Issues <https://github.com/jwodder/eletter/issues>`_\n| `Changelog <https://github.com/jwodder/eletter/blob/master/CHANGELOG.md>`_\n\n``eletter`` provides functionality for constructing & deconstructing\n``email.message.EmailMessage`` instances without having to touch the needlessly\ncomplicated ``EmailMessage`` class itself.  A simple function enables\ncomposition of e-mails with text and/or HTML bodies plus attachments, and\nclasses are provided for composing more complex multipart e-mails.\n\n\nInstallation\n============\n``eletter`` requires Python 3.8 or higher.  Just use `pip\n<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install\n``eletter`` and its dependencies::\n\n    python3 -m pip install eletter\n\n\nExamples\n========\n\nConstructing an e-mail with the ``compose()`` function:\n\n.. code:: python\n\n    import eletter\n\n    TEXT = (\n        \"Oh my beloved!\\n\"\n        \"\\n\"\n        \"Wilt thou dine with me on the morrow?\\n\"\n        \"\\n\"\n        \"We're having hot pockets.\\n\"\n        \"\\n\"\n        \"Love, Me\\n\"\n    )\n\n    HTML = (\n        \"<p>Oh my beloved!</p>\\n\"\n        \"<p>Wilt thou dine with me on the morrow?</p>\\n\"\n        \"<p>We're having <strong>hot pockets</strong>.</p>\\n\"\n        \"<p><em>Love</em>, Me</p>\\n\"\n    )\n\n    with open(\"hot-pocket.png\", \"rb\") as fp:\n        picture = eletter.BytesAttachment(\n            content=fp.read(),\n            filename=\"enticement.png\",\n            content_type=\"image/png\",\n        )\n\n    msg = eletter.compose(\n        subject=\"Meet Me\",\n        from_=\"me@here.qq\",\n        to=[eletter.Address(\"My Dear\", \"my.beloved@love.love\")],\n        text=TEXT,\n        html=HTML,\n        attachments=[picture],\n    )\n\n``msg`` can then be sent like any other ``EmailMessage``, say, by using\noutgoing_.\n\n.. _outgoing: https://github.com/jwodder/outgoing\n\nFor more complex e-mails, a set of classes is provided.  Here is the equivalent\nof the HTML-with-image e-mail with alternative plain text version from the\n``email`` `examples page`__ in the Python docs:\n\n__ https://docs.python.org/3/library/email.examples.html\n\n.. code:: python\n\n    from email.utils import make_msgid\n    import eletter\n\n    text = eletter.TextBody(\n        \"Salut!\\n\"\n        \"\\n\"\n        \"Cela ressemble \u00e0 un excellent recipie[1] d\u00e9jeuner.\\n\"\n        \"\\n\"\n        \"[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718\\n\"\n        \"\\n\"\n        \"--Pep\u00e9\\n\"\n    )\n\n    asparagus_cid = make_msgid()\n\n    html = eletter.HTMLBody(\n        \"<html>\\n\"\n        \"  <head></head>\\n\"\n        \"  <body>\\n\"\n        \"    <p>Salut!</p>\\n\"\n        \"    <p>Cela ressemble \u00e0 un excellent\\n\"\n        '        <a href=\"http://www.yummly.com/recipe/Roasted-Asparagus-'\n        'Epicurious-203718\">\\n'\n        \"            recipie\\n\"\n        \"        </a> d\u00e9jeuner.\\n\"\n        \"    </p>\\n\"\n        f'    <img src=\"cid:{asparagus_cid[1:-1]}\" />\\n'\n        \"  </body>\\n\"\n        \"</html>\\n\"\n    )\n\n    image = eletter.BytesAttachment.from_file(\n        \"roasted-asparagus.jpg\",\n        inline=True,\n        content_id=asparagus_cid,\n    )\n\n    msg = (text | (html ^ image)).compose(\n        subject=\"Ayons asperges pour le d\u00e9jeuner\",\n        from_=eletter.Address(\"Pep\u00e9 Le Pew\", \"pepe@example.com\"),\n        to=[\n            eletter.Address(\"Penelope Pussycat\", \"penelope@example.com\"),\n            eletter.Address(\"Fabrette Pussycat\", \"fabrette@example.com\"),\n        ],\n    )\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple e-mail composition & decomposition",
    "version": "0.5.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/jwodder/eletter/issues",
        "Documentation": "https://eletter.readthedocs.io",
        "Source Code": "https://github.com/jwodder/eletter"
    },
    "split_keywords": [
        "emailmessage",
        " e-mail",
        " email",
        " message"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea9f2e5e0e4f954cd0152932e5e5468bd51540fe71b622c1c5a4cc7e2b8ce3b8",
                "md5": "d6c8ea7bbe1b8b765040637d7f12ea9e",
                "sha256": "60553be28055db300ecaecb08291da867ba94d54c4dc3039b4d9b3a514ca3c27"
            },
            "downloads": -1,
            "filename": "eletter-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d6c8ea7bbe1b8b765040637d7f12ea9e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17601,
            "upload_time": "2024-12-01T12:38:03",
            "upload_time_iso_8601": "2024-12-01T12:38:03.164829Z",
            "url": "https://files.pythonhosted.org/packages/ea/9f/2e5e0e4f954cd0152932e5e5468bd51540fe71b622c1c5a4cc7e2b8ce3b8/eletter-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1866ecac389903536db0b01be1ea6f35525c4a3472cb09f9bf82f367baa4a4d0",
                "md5": "8a2dc111ba17c121f60faad3fbcfeeeb",
                "sha256": "9d2cccfeda5f98fde5798fa24ac2975c0aaaf158ca3c90a9474432abfe5dec83"
            },
            "downloads": -1,
            "filename": "eletter-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8a2dc111ba17c121f60faad3fbcfeeeb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 46450,
            "upload_time": "2024-12-01T12:38:05",
            "upload_time_iso_8601": "2024-12-01T12:38:05.251774Z",
            "url": "https://files.pythonhosted.org/packages/18/66/ecac389903536db0b01be1ea6f35525c4a3472cb09f9bf82f367baa4a4d0/eletter-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-01 12:38:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jwodder",
    "github_project": "eletter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "eletter"
}
        
Elapsed time: 1.81756s