Local Inbox Triage: private AI Gmail sorting with Ollama
$10
Sorts unread Gmail into Urgent / Needs Reply / FYI / Junk with a model running on your own computer. No API keys, no per-email cost, and your email never leaves your machine. Labels unread Gmail...
Read full descriptionDescription
Sorts unread Gmail into Urgent / Needs Reply / FYI / Junk with a model running on your own computer. No API keys, no per-email cost, and your email never leaves your machine.
What it does
- Labels unread Gmail with a local Ollama model (default
qwen3:4b: 29/30 on the included sample set, about 1 second per email on an 8 GB Mac) - Tell it who you are in one line and add your own examples; no prompt engineering needed
- Benchmark on your own mail: export, hand-label, and compare models by accuracy and speed
- A keyword fallback keeps labeling when Ollama is down
- Dry-run mode, idempotent reruns, and it never deletes, sends, or drafts email
- About 300 lines of readable Python with 3 dependencies and tests included
Try it safely first
python -m inbox_triage run --dry-runShows every decision without touching Gmail.
What you get
A ZIP with the Python package, a setup guide (Gmail API credentials in about 15 minutes), an example config, a 30-email benchmark set, and tests.
Not affiliated with or endorsed by Google. Gmail is a trademark of Google LLC. Provided as is; AI labels can be wrong, so review before relying on them.
Files included
local-inbox-triagelocal-inbox-triage
benchbench
- sample_emails.jsonsample_emails.json7.4 KB
- README.mdREADME.md5 KB
inbox_triageinbox_triage
- gmail.pygmail.py4.2 KB
- classifier.pyclassifier.py3.8 KB
- __main__.py__main__.py3 KB
- rules.pyrules.py2 KB
- config.pyconfig.py833 B
- __init__.py__init__.py161 B
teststests
- test_triage.pytest_triage.py2.5 KB
- config.example.jsonconfig.example.json358 B
- CHANGELOG.mdCHANGELOG.md124 B
- requirements.txtrequirements.txt73 B
- .gitignore.gitignore46 B
README
local-inbox-triage/README.md
Local Inbox Triage
Sorts your unread Gmail into Urgent, Needs Reply, FYI, and Junk labels using an AI model that runs on your own computer through Ollama.
- Private: email content never leaves your machine (as long as
ollama_urlpoints at your own computer, the default). No OpenAI or Anthropic key, no per-email cost. - Measurable: includes a benchmark so you can check accuracy on your mail before trusting it.
- Safe to rerun: already-labeled mail is skipped.
--dry-runshows decisions without touching Gmail. - Degrades gracefully: if Ollama is down, a conservative keyword fallback labels mail instead of failing.
- Small: ~300 lines of readable Python and three dependencies.
It only adds labels (and optionally archives Junk). It never deletes, sends, or drafts email.
Requirements
- macOS, Linux, or Windows with Python 3.9+
- Ollama and about 3 GB of free RAM for the default model (an 8 GB Mac is fine)
- A Gmail or Google Workspace account
Setup (about 15 minutes)
1. Install
pip install -r requirements.txt
ollama pull qwen3:4b2. Create Gmail API credentials (one time; Google requires your own)
- Go to https://console.cloud.google.com/, then create a project.
- Go to APIs & Services → Library, then enable Gmail API.
- Go to APIs & Services → OAuth consent screen, choose External, and add your own address as a test user.
- Go to APIs & Services → Credentials → Create credentials → OAuth client ID, choose Desktop app, then Download JSON.
- Save the downloaded file as
~/.config/local-inbox-triage/credentials.json.
3. Configure
cp config.example.json config.jsonEdit config.json:
| Key | What it does |
|---|---|
about_me | One line about you. The model uses it to judge what matters ("a freelance designer", "a nurse"). |
model | Any Ollama model name. |
gmail_query | Which mail to look at, in Gmail search syntax. |
max_emails | Upper limit per run. |
label_prefix | Labels are created as Triage/Urgent, Triage/Needs Reply, and so on. |
archive_junk | true removes Junk from the inbox. It stays in All Mail. Default false. |
never_junk_senders | Address fragments that must never be marked Junk. |
extra_examples | Your own one-line examples, such as "\"Rent due in 2 days\" -> URGENT". |
4. Try it without changing anything
python -m inbox_triage run --dry-runThe first run opens a browser to authorize Gmail. The token is saved with owner-only permissions.
5. Run it for real
python -m inbox_triage runRun it automatically
macOS/Linux (cron), every 15 minutes:
*/15 * * * * cd /path/to/local-inbox-triage && /usr/bin/python3 -m inbox_triage run >> triage.log 2>&1Windows: create a Task Scheduler task that runs the same command.
Check accuracy on your own mail
The included bench/sample_emails.json has 30 synthetic emails. To measure accuracy on your own mail:
python -m inbox_triage export --out my_emails.json # dumps recent mail locally
# open my_emails.json and fill in each "expected" field; use "FYI|JUNK" if either is fine
python -m inbox_triage bench --file my_emails.json qwen3:4b llama3.1:8bIt prints accuracy, seconds per email, and every miss, so you can compare models and tune
about_me and extra_examples. my_emails.json contains your real mail, so don't share it.
Choosing a model
| Model | RAM | Notes |
|---|---|---|
qwen3:4b (default) | ~3 GB | 29/30 on the included sample set, about 1 second per email on an 8 GB M-series Mac |
llama3.1:8b | ~5 GB | Needs 16 GB of RAM or more. On an 8 GB Mac it spills to the CPU and becomes very slow. |
Measure on your own mail with bench rather than trusting any table, this one included.
Troubleshooting
- "Ollama unreachable … used keyword rules": start Ollama (
ollama serve, or open the app). Missing credentials.json: redo setup step 2 and check the file path.- Google says "app not verified": expected for your own test app. Choose Advanced → Continue.
- Token expired after 7 days: Google expires tokens for apps in "Testing". Delete
~/.config/local-inbox-triage/token.jsonand rerun, or publish the consent screen.
Tests
pip install pytest && python -m pytest testsDisclaimer
This software is provided "as is", without warranty of any kind. An AI model can and will
mislabel some email, including important email; check the Triage/Junk label now and then,
and leave archive_junk off until bench shows it is accurate on your mail. You run it with
your own Google credentials and are responsible for how it is used on your account. The
author is not liable for missed, mislabeled, or archived email or any resulting loss.
Not affiliated with or endorsed by Google. Gmail is a trademark of Google LLC. The sample
emails in bench/ are fictional; company names appear only to make the examples realistic.
Reviews
No reviews