Send and process e-mail from any Python process — a one-off script, a worker or a production API. SMTP sends, one connection per message or one session for many; IMAP reads a mailbox incrementally, files, marks, moves and deletes. Every failure says who has to act and whether to retry, decided from the codes SMTP and IMAP define, never from a provider's wording.
pip install forktex-mail
from forktex_mail import Mailbox, compose, fetch, send
box = Mailbox(host="mail.example.com", user="me@example.com", password="…", sender_name="Me")
sent = await send(box, compose(box, to="Ana <ana@example.com>", subject="Hello", text="Hi!", html="<p>Hi!</p>"))
inbox = await fetch(box, unseen=True)
Requirements
| Python | 3.14 |
| A mail server | Any SMTP submission server to send; IMAP to read, file and process. Battle-tested against Zoho Mail, Postfix and Dovecot, and GreenMail. |
| Sign-in | A password (or an app password), or an OAuth2 access token for providers that require one (Microsoft 365, Outlook.com, Gmail). |
| TLS | Implicit TLS or STARTTLS, verified against the system's authorities or a private one you supply. Plain SMTP only for a local catcher, without credentials. |
What you can build
| You want to | Read |
|---|---|
| Describe a mailbox once, from settings or a database row | A mailbox |
| Send from a script, an API or a worker | Send from a script, Send from an API |
| Send many messages on one logged-in connection | Send many messages |
Attach files, thread replies, add List-Unsubscribe |
Attachments, threads and headers |
| Stay under a host's sending caps | Stay under a sending cap |
| Sign in to Microsoft 365, Outlook.com or Gmail with OAuth2 | Sign in with OAuth2 |
| Read a mailbox, read on from where you stopped, or read a whole folder in batches | Read a mailbox |
| File sent mail, mark, move and delete — process an inbox | Process an inbox |
| Find out which messages bounced, and why | Read bounces |
| Decide whether to retry, fix settings or drop a message | Decide what to do with a failure |
| Test your own code that sends mail, without a server | Test code that sends mail |
How it works
| Concept | What it is |
|---|---|
| Mailbox | One account's settings: hosts, sign-in, sender, TLS. Pure data; never reads the environment. |
| Transport | Anything that sends a message, says what the server did, and closes: Smtp, or Capture in tests. |
| Session | async with Smtp(mailbox): one login for many messages, checked before each and reconnected when gone. |
| Received | A message read back: who it is from_ and to, text, HTML, attachments, every header, the server's flags and arrival time, and — for a delivery report — its bounce. Reading never fails on a message. |
| UID and UIDVALIDITY | A message's identity in a folder. Keep both, read on with after_uid (or read a whole folder with messages), act on messages with mark, move, delete. |
| MailError | Every failure, with a kind that says who has to act: invalid, config, auth, tls, unreachable, deferred, rejected, or unknown when no usable answer came after the whole message was sent. |
Things to know
| Acceptance is not delivery | Sent is what the submission server took. Unknown recipients often come back later as a bounce; read them with fetch and match bounce.original_message_id. |
| The TLS mode follows the port | Implicit TLS on 465 and 993, STARTTLS elsewhere, unless security (SMTP) and imap_security (IMAP) — set independently — say otherwise. A port spoken to in the wrong mode fails at once as tls, naming the setting. |
| Results are JSON-ready | Received, Sent, Fetched and the rest are frozen values whose JSON keys are camelCase (messageId, receivedAt; the author is "from"), for storing or queueing; Python code uses the field names. |
| Nothing is sent twice by the library | A session checks its connection before a message and never retries after one; retrying is the caller's decision, guided by transient. |
| Changes need the folder's UIDVALIDITY | mark, move and delete refuse UIDs from a folder that has since been rebuilt. |
| Providers differ, the model does not | Relays and mailboxes, a replaced Message-ID, Gmail's delete-means-archive, folders under INBOX. — each is handled or documented in Operating. |
Documentation
| Page | For |
|---|---|
| Guide | Runnable recipes for each way to use it |
| Reference | Every public name, setting and error |
| Operating | Providers, TLS, sending caps, bounces, what to watch |
Stability
From 1.0.0, semantic versioning covers every name in forktex_mail.__all__,
the eight error kinds and the AppErrorCode each maps to. Anything else —
module paths included — is internal. Changes are listed in the
CHANGELOG.
Contributing
Working on forktex-mail itself? Start with
docs/development.md. Security issues go to the
address in SECURITY.md.
Licence
AGPL-3.0-or-later, or a commercial licence from FORKTEX S.R.L. See LICENSE and NOTICE.
Metadata
Release files for forktex-mail 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| forktex_mail-1.0.0.tar.gz | 266.3 kB | Without provenance | Details for forktex_mail-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| forktex_mail-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for forktex_mail-1.0.0-py3-none-any.whl |
Total release size: 301.0 kB
Release files / forktex_mail-1.0.0.tar.gz
| Download URL | forktex_mail-1.0.0.tar.gz |
|---|---|
| Size | 266.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2312e28ffa566660da5725a93c82fbfed28551c5e5717b380f073a8209e69066
|
|
BLAKE2b-256 checksum How to use checksums |
ec04337fac7b190b0d6fbd8eacf41ec4b72404b806dda036b4c6e5f3b61c4ee6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / forktex_mail-1.0.0-py3-none-any.whl
| Download URL | forktex_mail-1.0.0-py3-none-any.whl |
|---|---|
| Size | 34.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7b30205c7ece433f5e5a2ca7da2208f9136935f6d46bd954a5329be2c1fdbc1
|
|
BLAKE2b-256 checksum How to use checksums |
61369b4a2fd8e0bc1e54cbc90ff7b474f351fa998718cc50ebea1d6d96a25b14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Security for forktex-mail 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.