An autonomous agent that scans your inbox from a saved checkpoint, classifies each email (OTP / social / promotional / keep), and moves trashable mail to Trash — resuming exactly where it left off on the next scheduled run. No re-scanning the whole inbox; no duplicate processing.
- Enable 2-Step Verification on your Google account.
- Create an App Password: https://myaccount.google.com/apppasswords
(a 16-character code, e.g.
abcd efgh ijkl mnop— enter without spaces). - Copy
.env.example->.envand set: GMAIL_MODE=imap GMAIL_USER_EMAIL=you@gmail.com GMAIL_APP_PASSWORD=xxxxxxxxxxxxcccc uv run python -m gmail_agent.cli run --dry-run(preview, no trashing)uv run python -m gmail_agent.cli run(live — moves trash)
-
Create a Google Cloud project, enable Gmail API, create OAuth Desktop credentials, download as
credentials.jsoninto this folder. -
Copy
.env.example->.env, setGMAIL_USER_EMAIL,GMAIL_MODE=oauth. -
uv run python -m gmail_agent.cli auth(opens browser, saves token.json) -
uv run python -m gmail_agent.cli run --dry-run(preview, no trashing) -
uv run python -m gmail_agent.cli run(live — moves trash) -
Schedule it (cron / Task Scheduler) to run daily.
runone pass, resumes from checkpointrun --dry-runanalyze onlyrun --max Ncap emails this passstatusshow checkpoint + errored idsauthperform OAuth (no-op in IMAP mode; prints a hint)
- OTP expired -> Trash
- Social notifications (LinkedIn/FB/IG/X/Threads/...) -> Trash
- Promotional (sales/coupons/newsletters/...) -> Trash
- Everything else -> Keep
DRY_RUN=trueanalyzes but never trashes.- Checkpoint saved after every email -> crash-safe, resumable.
- Failed emails logged + retried next run; never blocks the queue.
uv run pytest -q (no Gmail needed — client is mocked)