🧹 Shiny Gmail Automation β€” AI inbox cleaner (3 workflows, 55 nodes, β‚±0 budget)

Hey everyone! :waving_hand:

Sharing my first n8n build here!

I had around 7,000 emails sitting in my Gmail inbox and I was too lazy to clean them manually β€” so I built an automation to do it for me.

What it does

Every morning at 6 AM, it:

  • Fetches unprocessed inbox emails
  • Checks my Telegram sender/domain rules first
  • If no rule exists, asks Gemini AI to classify the email
  • Applies a Gmail label (priority, receipts, unimportant, email-subs, or please-review)
  • Archives it out of my inbox
  • Sends me a Telegram summary when it’s done

If AI is unsure about an email, it goes to please-review β€” it never guesses silently.

I can also manage rules straight from Telegram:
/whitelist boss@company.com β†’ priority
/blacklistdomain spammy-site.com β†’ unimportant
/receipt orders@store.com β†’ receipts

Architecture

Workflow Nodes Purpose
A β€” Daily Orchestrator 25 Fetches inbox, applies rules, calls child, summarizes
B β€” Email Processor 19 Classifies and labels one email at a time
C β€” Telegram Rules Manager 11 Manage rules via Telegram bot

55 nodes total. Budget: β‚±0.

Stack

n8n (self-hosted) + Gemini AI + Gmail API + Telegram Bot + Neon Postgres + ngrok

Everything runs on free tier.

Some n8n gotchas I discovered (might help others!)

During deployment I ran into a few issues that took a while to figure out:

  1. Import wiring corruption β€” IF, Switch, and SplitInBatches nodes can have internally corrupted output mappings after JSON import. The wires look correct visually but route data to the wrong outputs during execution. Fix: delete the node and recreate it from scratch.

  2. SplitInBatches infinite loop β€” If your Wait node accidentally loops back to a node before SplitInBatches instead of directly back to it, the batch restarts from item 1 forever. Caught this one after 60+ loops. :sweat_smile:

  3. Gmail metadata capitalization β€” Gmail returns From, Subject, Date (capitalized) but code might expect lowercase from, subject, date. Need to check both or all your emails show empty sender and β€œ(no subject)”.

All documented in the deployment guide with step-by-step fixes.

Links

:link: GitHub: GitHub - chanrylejay/shiny-gmail-automation: AI-powered Gmail inbox cleanup on n8n β€” Gemini sorts your emails, Gmail labels track everything, Telegram lets you set the rules. 54 nodes, 3 workflows, zero inbox stress. Β· GitHub

Full deployment guide, troubleshooting, and schema included. MIT License.

About me

I’m not a developer β€” I’m a non-technical automation builder from Manila. This is my first GitHub project and my first n8n community post!

Built it because I was lazy. Stayed because it actually works. :grinning_face_with_smiling_eyes:

Would love feedback, ideas, or questions! :rocket:

2 Likes

Nice first build - the orchestrator/processor split across Workflow A and B is a smart pattern, keeps the per-email logic clean and reusable. The Telegram rule manager on top makes it genuinely practical to use daily without touching n8n. How are you handling Gemini classification accuracy - do you tune the prompt per label or use a single prompt with all categories listed?

1 Like

Thank you! :grinning_face_with_smiling_eyes: Yeah, for Gemini I’m using one main prompt with all the categories listed, not separate prompts per label.

I didn’t really try to make Gemini perfect. I made it conservative instead. If it’s confident, it labels the email. If it’s unsure, low confidence, or the API fails, it sends the email to please-review instead of forcing a bad category.

A few things that helped:

  • I use a strict JSON response with fixed categories:
    unimportant, receipts, priority, email-subs, and please-review

  • I keep the temperature low at 0.1 so the output stays consistent instead of getting too creative

  • I only send metadata to Gemini, like sender, subject, and snippet β€” no full email body

  • I have fallback rules for uncertainty:
    confidence below 0.8 β†’ please-review
    invalid category β†’ please-review
    API or parse issues β†’ please-review

Then for repeat senders or domains, I use Telegram rules so they can skip Gemini completely.

So the setup is basically: one structured prompt, strict categories, conservative fallback, and rules for the obvious stuff.

The metadata-only approach is smart - keeps token usage low and avoids any privacy concerns with full email content going to the API. The Telegram bypass for repeat senders is a nice touch too, saves unnecessary API calls for known senders. That confidence threshold setup should make the system pretty reliable in practice.

2 Likes