Search, back up, export and clean up any IMAP mailbox in Python, with Gmail-style queries and rules.

The complete version of our reading emails tutorial: a Gmail-style search language for any IMAP server, robust parsing of real-world emails, incremental backups to .eml files with a full-text search index, exports to a browsable HTML archive, mbox and CSV, attachment downloads, rules that always dry-run first, inbox insights and a newsletter unsubscribe finder.
Upgrades the free tutorial: How to Read Emails in Python
Everything the tutorial leaves as an exercise, done properly.
from:, has:attachment, is:unread, larger:5M, older:30d, OR, NOT... on any IMAP server.
.eml files + a SQLite full-text index; only new mail is downloaded next time.
Export a searchable archive that opens in any browser, plus mbox and CSV.
Download attachments by query, organised by year and sender, duplicates skipped.
Move, mark, flag and save attachments by query; always a dry run before --apply.
Top senders, volume per month, and the newsletters you never read.
Read-only browsing that never marks mail as read, TLS, no plain-text passwords.
13 pytest tests plus a --demo mailbox to try every command safely.
Real output of the tools. Sample data is used wherever a screenshot would show private information (networks, emails, processes).
The tutorial is great for learning the basics. This is the version you'd actually ship.
| Free tutorial | Email Toolkit Pro | |
|---|---|---|
| Search | Fetch the latest N | A full query language |
| Parsing | Basic | Charsets, HTML-only mail, RFC 2231 names |
| Backups | — | ✓ incremental, full-text searchable |
| Exports | — | HTML archive, mbox, CSV |
| Rules | — | ✓ with dry run |
| Insights + unsubscribe finder | — | ✓ |
| Tests | — | 13 pytest tests |
Clean, commented, modular Python. Here's the start of mailkit/query.py:
def to_imap(q: Query, today: Optional[date] = None) -> List[str]:
"""IMAP SEARCH criteria tokens (implicitly ANDed). OR takes exactly two
search keys, and "NOT FROM x" or "OR a b" each count as one key."""
if not q.groups:
return ["ALL"]
out: List[str] = []
for g in q.groups:
parts = [_imap_term(t, today) for t in g]
crit = parts[-1]
for p in reversed(parts[:-1]):
crit = ["OR"] + p + crit
out += crit
return out
The Python Tools Pro Pack includes Email Toolkit Pro plus our other premium tools, for $21.75 instead of $65 when bought one by one.
What's in the pack?
Python 3.8 or newer with rich (keyring optional). Any IMAP account: Gmail, Outlook, Yahoo and iCloud need an app password. Every command has a --demo mode with a sample mailbox.
You're sent straight to your download page, and we email you the link too. The link keeps working, so you can re-download updated versions later. Lost it? Recover your downloads with your email.
If you've followed our free tutorial, yes. The code is split into small, commented modules, and the README walks through the architecture. It's the ideal next step after the tutorial.
Yes. You can modify it, learn from it, and ship your own tools and apps built on it, even commercially. The only thing you can't do is redistribute or resell the source code itself.
Email us within 14 days and we'll refund you. No questions asked.
$11.25 one-time. Instant download, free updates.
A live system dashboard in Python: terminal and web UIs, smart alerts, recordings and HTML reports
Scan, analyse and improve your Wi-Fi in Python: best channel, security checkup, site survey and reports
Global hotkeys, a text expander and a macro recorder in Python that work in every app
Transcripts and subtitles from any audio or video in Python, locally or with the OpenAI and Groq APIs
All five premium Python games in one download: Tetromino, Flappy Wings, Chess, Snake and Platformer Pro