|
1 | 1 | python-emails |
2 | | -~~~~~~~~~~~~~ |
| 2 | +============= |
3 | 3 |
|
4 | | -Modern python library for email. |
| 4 | +.. |pypi| image:: https://img.shields.io/pypi/v/emails.svg |
| 5 | + :target: https://pypi.org/project/emails/ |
| 6 | + :alt: PyPI version |
5 | 7 |
|
6 | | -Build message: |
| 8 | +.. |python| image:: https://img.shields.io/pypi/pyversions/emails.svg |
| 9 | + :target: https://pypi.org/project/emails/ |
| 10 | + :alt: Python versions |
7 | 11 |
|
8 | | -.. code-block:: python |
| 12 | +.. |tests| image:: https://github.com/lavr/python-emails/workflows/Tests/badge.svg?branch=master |
| 13 | + :target: https://github.com/lavr/python-emails/actions?query=workflow%3ATests |
| 14 | + :alt: Test status |
| 15 | + |
| 16 | +.. |docs| image:: https://readthedocs.org/projects/python-emails/badge/?version=latest |
| 17 | + :target: https://python-emails.readthedocs.io/ |
| 18 | + :alt: Documentation status |
| 19 | + |
| 20 | +.. |license| image:: https://img.shields.io/pypi/l/emails.svg |
| 21 | + :target: https://github.com/lavr/python-emails/blob/master/LICENSE |
| 22 | + :alt: License |
| 23 | + |
| 24 | +|pypi| |python| |tests| |docs| |license| |
| 25 | + |
| 26 | +Build, transform, and send emails in Python with a high-level API. |
9 | 27 |
|
10 | | - >>> import emails |
11 | | - >>> message = emails.html(html="<p>Hi!<br>Here is your receipt...", |
12 | | - subject="Your receipt No. 567098123", |
13 | | - mail_from=('Some Store', 'store@somestore.com')) |
14 | | - >>> message.attach(data=open('bill.pdf', 'rb'), filename='bill.pdf') |
| 28 | +``python-emails`` helps you compose HTML and plain-text messages, attach files, |
| 29 | +embed inline images, render templates, apply HTML transformations, sign with |
| 30 | +DKIM, and send through SMTP without hand-building MIME trees. |
15 | 31 |
|
16 | | -send message and get response from smtp server: |
| 32 | + |
| 33 | +Why python-emails |
| 34 | +----------------- |
| 35 | + |
| 36 | +- A concise API over ``email`` and ``smtplib`` |
| 37 | +- HTML and plain-text messages in one object |
| 38 | +- File attachments and inline images |
| 39 | +- CSS inlining, image embedding, and HTML cleanup |
| 40 | +- Jinja2, Mako, and string template support |
| 41 | +- DKIM signing |
| 42 | +- Loaders for URLs, HTML files, directories, ZIP archives, and RFC 822 messages |
| 43 | +- SMTP sending with SSL/TLS support |
| 44 | +- Async sending via ``aiosmtplib`` |
| 45 | + |
| 46 | + |
| 47 | +Quick Example |
| 48 | +------------- |
17 | 49 |
|
18 | 50 | .. code-block:: python |
19 | 51 |
|
20 | | - >>> r = message.send(to='s@lavr.me', smtp={'host': 'aspmx.l.google.com', 'timeout': 5}) |
21 | | - >>> assert r.status_code == 250 |
| 52 | + import emails |
22 | 53 |
|
23 | | -and more: |
| 54 | + message = emails.html( |
| 55 | + subject="Your receipt", |
| 56 | + html="<p>Hello!</p><p>Your payment was received.</p>", |
| 57 | + mail_from=("Billing", "billing@example.com"), |
| 58 | + ) |
| 59 | + message.attach(filename="receipt.pdf", data=open("receipt.pdf", "rb")) |
24 | 60 |
|
25 | | -* DKIM signature |
26 | | -* Render body from template |
27 | | -* Flask extension and Django integration |
28 | | -* HTML transformation with CSS inlining (``pip install emails[html]``) |
29 | | -* Load message from url or from file |
| 61 | + response = message.send( |
| 62 | + to="customer@example.com", |
| 63 | + smtp={ |
| 64 | + "host": "smtp.example.com", |
| 65 | + "port": 587, |
| 66 | + "tls": True, |
| 67 | + "user": "billing@example.com", |
| 68 | + "password": "app-password", |
| 69 | + }, |
| 70 | + ) |
| 71 | + assert response.status_code == 250 |
30 | 72 |
|
31 | | -| |
32 | 73 |
|
33 | | -Documentation: `python-emails.readthedocs.io <https://python-emails.readthedocs.io/>`_ |
| 74 | +Installation |
| 75 | +------------ |
34 | 76 |
|
35 | | -Flask extension: `flask-emails <https://github.com/lavr/flask-emails>`_ |
| 77 | +Install the lightweight core: |
36 | 78 |
|
37 | | -| |
38 | | -| |
| 79 | +.. code-block:: bash |
| 80 | +
|
| 81 | + pip install emails |
| 82 | +
|
| 83 | +Install HTML transformation features such as CSS inlining, image embedding, |
| 84 | +and loading from URLs or files: |
| 85 | + |
| 86 | +.. code-block:: bash |
| 87 | +
|
| 88 | + pip install "emails[html]" |
| 89 | +
|
| 90 | +Install Jinja2 template support for the ``JinjaTemplate`` class: |
| 91 | + |
| 92 | +.. code-block:: bash |
| 93 | +
|
| 94 | + pip install "emails[jinja]" |
| 95 | +
|
| 96 | +Install async SMTP sending support for ``send_async()``: |
| 97 | + |
| 98 | +.. code-block:: bash |
| 99 | +
|
| 100 | + pip install "emails[async]" |
| 101 | +
|
| 102 | +
|
| 103 | +Common Tasks |
| 104 | +------------ |
| 105 | + |
| 106 | +- Build and send your first message: |
| 107 | + `Quickstart <https://python-emails.readthedocs.io/en/latest/quickstart.html>`_ |
| 108 | +- Configure installation extras: |
| 109 | + `Install guide <https://python-emails.readthedocs.io/en/latest/install.html>`_ |
| 110 | +- Inline CSS, embed images, and customize HTML processing: |
| 111 | + `Advanced Usage <https://python-emails.readthedocs.io/en/latest/advanced.html>`_ |
| 112 | +- Learn the full public API: |
| 113 | + `API Reference <https://python-emails.readthedocs.io/en/latest/api.html>`_ |
| 114 | +- Troubleshoot common scenarios: |
| 115 | + `FAQ <https://python-emails.readthedocs.io/en/latest/faq.html>`_ |
| 116 | +- Explore alternatives and related projects: |
| 117 | + `Links <https://python-emails.readthedocs.io/en/latest/links.html>`_ |
| 118 | + |
| 119 | + |
| 120 | +What You Get |
| 121 | +------------ |
| 122 | + |
| 123 | +- Message composition for HTML, plain text, headers, CC/BCC, and Reply-To |
| 124 | +- Attachments, inline images, and MIME generation |
| 125 | +- Template rendering in ``html``, ``text``, and ``subject`` |
| 126 | +- HTML transformations through ``message.transform()`` |
| 127 | +- SMTP delivery through config dicts or reusable backend objects |
| 128 | +- Django integration via ``DjangoMessage`` |
| 129 | +- Flask integration via `flask-emails <https://github.com/lavr/flask-emails>`_ |
| 130 | + |
| 131 | + |
| 132 | +When To Use It |
| 133 | +-------------- |
| 134 | + |
| 135 | +Use ``python-emails`` when you need more than a minimal plain-text SMTP call: |
| 136 | +HTML emails, attachments, inline images, template rendering, DKIM, message |
| 137 | +loading from external sources, or a cleaner API than hand-written |
| 138 | +``email.mime`` code. |
| 139 | + |
| 140 | +If you only need to send a very small plain-text message and want zero |
| 141 | +dependencies, the standard library may be enough. |
| 142 | + |
| 143 | + |
| 144 | +Documentation |
| 145 | +------------- |
| 146 | + |
| 147 | +- `Documentation home <https://python-emails.readthedocs.io/>`_ |
| 148 | +- `Quickstart <https://python-emails.readthedocs.io/en/latest/quickstart.html>`_ |
| 149 | +- `Advanced Usage <https://python-emails.readthedocs.io/en/latest/advanced.html>`_ |
| 150 | +- `API Reference <https://python-emails.readthedocs.io/en/latest/api.html>`_ |
| 151 | +- `FAQ <https://python-emails.readthedocs.io/en/latest/faq.html>`_ |
| 152 | + |
| 153 | + |
| 154 | +Project Status |
| 155 | +-------------- |
| 156 | + |
| 157 | +``python-emails`` is production/stable software and currently supports |
| 158 | +Python 3.10 through 3.14. |
| 159 | + |
| 160 | + |
| 161 | +Contributing |
| 162 | +------------ |
| 163 | + |
| 164 | +Issues and pull requests are welcome. |
| 165 | + |
| 166 | +- `Report a bug or request a feature <https://github.com/lavr/python-emails/issues>`_ |
| 167 | +- `Source code on GitHub <https://github.com/lavr/python-emails>`_ |
| 168 | +- `How to Help <https://python-emails.readthedocs.io/en/latest/howtohelp.html>`_ |
39 | 169 |
|
40 | | -.. image:: https://github.com/lavr/python-emails/workflows/Tests/badge.svg?branch=master |
41 | | - :target: https://github.com/lavr/python-emails/actions?query=workflow%3ATests |
42 | 170 |
|
43 | | -.. image:: https://img.shields.io/pypi/v/emails.svg |
44 | | - :target: https://pypi.python.org/pypi/emails |
| 171 | +License |
| 172 | +------- |
45 | 173 |
|
| 174 | +Apache 2.0. See `LICENSE <https://github.com/lavr/python-emails/blob/master/LICENSE>`_. |
0 commit comments