Automatically classifies and labels Gmail emails using Google Apps Script + Gemini AI. Zero infrastructure — runs entirely inside Google.
A time-based trigger runs every 10 minutes, picks up unlabeled emails, sends them to Gemini 2.0 Flash Lite for classification, and applies the appropriate Gmail label. That's it.
| Label | What goes here |
|---|---|
| Jobs/Recruiter | Job opportunities, recruiter outreach, interviews |
| Finance | Investments, stocks, mutual funds, tax, insurance, salary |
| Transactions | UPI, credit card spends, bank debits, bill payments |
| Travel | Flight bookings, hotel reservations, boarding passes |
| Rides | Uber, Ola, Rapido trips and receipts |
| Dining | Restaurant reservations, dine-in confirmations |
| Food | Swiggy/Zomato food delivery orders |
| Splitwise | Expense splits, settlements, balance updates |
| Shopping | Orders, deliveries, returns, tracking |
| GitHub | PRs, issues, CI/CD, code reviews |
| Newsletters | Blog digests, weekly roundups, content subscriptions |
| Social | LinkedIn, Twitter, Instagram notifications |
| Promotions | Marketing emails, deals, discount offers |
| Personal | Direct personal emails |
| System | OTPs, verification codes, password resets, security alerts |
- Go to Google Apps Script and create a new project
- Paste the contents of
Code.gs - Replace
YOUR_GEMINI_API_KEYwith your key from Google AI Studio - Enable the Gmail Advanced Service: Services (+) → Gmail API → Add
- Run
setupTrigger()to start automatic labeling every 10 minutes - Run
colorizeLabels()to add colors to the labels
| Function | What it does |
|---|---|
classifyAndLabelEmails() |
Process next batch of unlabeled emails |
bulkLabel7Days() |
Backfill labels for the last 7 days |
bulkLabel30Days() |
Backfill labels for the last 30 days |
reclassifyDining() |
Strip Dining labels and re-classify on next run |
reclassifyAll() |
Strip all labels and re-classify everything |
removeDuplicateLabels() |
Fix emails that ended up with multiple labels |
deleteOldLabels() |
Delete labels not in the active list |
setupTrigger() |
Set up the 10-minute auto-trigger |
removeTrigger() |
Stop automatic labeling |
Uses Gemini 2.0 Flash Lite which has a free tier. At 10 emails per 10 minutes, you stay well within limits.