n8n Workflow – Gmail AI Auto-Sorter

AI Automation & Workflows\\Jul 10, 2025

I Built an AI That Sorts My Gmail So I Don’t Have To

Bottom line up front: I was spending way too much time sorting emails across 5 Gmail accounts, so I built an AI workflow that does it automatically. It runs every 15 minutes, categorizes everything with surprising accuracy, and costs about 70 cents a day. You can have the whole thing for free.

I’ll be honest. Email organization is not exciting. But neither is losing two hours every week playing inbox whack-a-mole across 5 different Gmail accounts while important stuff gets buried under newsletter spam.

I’m Mohit Aneja. I’ve been building things on the web for 17 years, and I run AixonAI. Last year I got tired of email chaos and decided to fix it properly.

My Gmail Was a Disaster

Here’s what my Monday mornings looked like: Open Gmail, see 50+ new emails across 5 accounts, start manually dragging things into folders, get distracted by something urgent, abandon the whole mess, repeat next week.

The problem wasn’t discipline or better folders. I tried all that. The problem was that email sorting requires actual intelligence. You need to read the content, understand the context, and make decisions.

Computers are supposed to be good at repetitive tasks, but email sorting isn’t really repetitive. Every email is different. A message from my bank about a security alert needs different treatment than a newsletter about productivity tips, even if they both mention “account management.”

So I thought: what if I could teach AI to read my emails the way I do?

Build Something That Actually Works

I needed a system that could:

  • Read every incoming email completely
  • Understand context, not just keywords
  • Make smart categorization decisions
  • Apply Gmail labels automatically
  • Run continuously without breaking
  • Handle edge cases gracefully

The tech stack was pretty obvious. n8n for workflow automation, OpenAI’s GPT-4o-mini for the intelligence, Gmail API for the actions. The hard part was getting the logic right.

How I Actually Built This Thing

The Core Workflow

Every 15 minutes, the system wakes up and checks for new emails that don’t already have custom labels. It grabs each one and sends the subject, sender, and content to GPT-4o-mini with a specific prompt.

The prompt was tricky to get right. Too vague and you get inconsistent results. Too specific and it breaks on edge cases. Here’s what I settled on:

You are an intelligent email assistant. Analyze this email and assign it to exactly one category.

Email subject: [SUBJECT]
Sender: [SENDER]
Content: [CONTENT]

Categories: priority, business, newsletter, administrative, personal, notifications, support, finance, travel, events, shopping, security, marketing, urgent, review, hr, it

Return only the category name in lowercase.

That’s it. Simple, direct, hard to misinterpret.

The Smart Parts

The workflow does a few clever things:

Label mapping: The AI returns something like “business” but Gmail needs the actual label ID like “Label_1901104473924568496”. So there’s a lookup system that matches AI responses to real Gmail labels.

Auto-creation: If a label doesn’t exist, the system creates it automatically. This only happens during setup, but it means you don’t have to manually create 17 different labels.

Error handling: If the AI can’t categorize something or returns gibberish, the email just stays unlabeled. No crashes, no retries, no drama.

Batch processing: There’s also a manual mode for processing existing emails in bulk. Useful for the initial cleanup.

The Categories

I ended up with 17 categories that cover pretty much everything:

Work stuff: Priority, Business, Administrative, HR, IT, Review Communication: Personal, Support, Notifications
Content: Newsletter, Marketing Life stuff: Finance, Shopping, Travel, Events, Security Catch-all: Urgent (for time-sensitive things that aren’t quite priority)

The AI is surprisingly good at these distinctions. It understands that a password reset email is “security” even if it comes from a shopping site. It knows that a meeting request is “business” even if it mentions personal topics.

The Weird Gotchas

A few things I learned the hard way:

Gmail’s label system is strange. When you create a label via API, Gmail assigns it a random ID like “Label_1234567890”. You have to store these mappings or the workflow breaks.

OpenAI sometimes gets creative. Even with a specific prompt, it occasionally returns “business/administrative” or adds explanations. I had to add validation to catch this.

Rate limits matter. Processing 100 emails at once will hit Gmail’s API limits. The batch processor now handles 5 emails at a time with delays.

Cost can sneak up. At about $0.15 per 1000 API calls, a busy day can cost more than expected. I added safeguards to prevent runaway charges.

It Actually Works

I’ve been running this for about eight months now. The results:

Time saved: I went from spending chunks of time every few days sorting email to maybe five minutes a week checking that everything looks right.

Accuracy: The AI gets it right most of the time. When it’s wrong, it’s usually close enough that I don’t care, or wrong in obvious ways that are easy to fix.

Cost: About $20-25 per month for my email volume. Worth it.

Reliability: It’s broken maybe three times, always due to API changes or credential expiration. Each time took about ten minutes to fix.

The thing I didn’t expect is how much mental space this freed up. I don’t think about email organization anymore. I just check the “Priority” label when I need to see important stuff, or browse “Finance” when I’m looking for receipts. The cognitive load is gone.

The Technical Details

If you want to build this yourself, here’s what you need:

n8n account (free tier works fine) Gmail with API access (requires Google Cloud setup) OpenAI API key (pay-per-use, about $0.0015 per email)

The workflow file is about 800 lines of JSON. Most of it is node configuration and credential mapping. The actual logic is maybe 50 lines of JavaScript for the label lookup and error handling.

Setup takes about 30 minutes if you know what you’re doing, maybe an hour if you’re new to n8n. Most of that time is getting the Gmail OAuth working properly.

Getting Your Own Copy

I’m releasing the complete workflow as a free download. You get the n8n JSON file, setup documentation, and troubleshooting guide.

Download the Gmail AI Auto-Sorter n8n Workflow

Why free? Because email chaos is a universal problem and this solution works. I’d rather see a thousand people using it than charge for something that actually solves a real problem.

The documentation walks you through everything. I wrote it for someone who’s never used n8n before but isn’t afraid of following technical instructions. The workflow itself is solid – I’ve been running it for months without issues.

If you need customization or run into problems, I do consulting at $30/hour. But honestly, most people won’t need that. The workflow is pretty robust.

The Real Point

This isn’t really about email. It’s about using AI for the right things.

AI is terrible at creative work, questionable at writing, and overhyped for most business applications. But it’s genuinely excellent at pattern recognition and repetitive decision-making. Email categorization is a perfect fit.

The real win isn’t the time saved. It’s the mental overhead removed. One less thing to think about. One less source of low-level stress.

I’ve got the workflow running on all 5 of my Gmail accounts now. My main personal one, a project-specific account, one for AixonAI, a client work account, and a testing account. Same setup, different labels for different contexts. It just works.

Anyway, that’s the story. Built a thing, it solved a problem, sharing it in case it helps you too.


I’m Mohit Aneja. I build automation solutions and run AixonAI. If you’re dealing with repetitive tasks that require some intelligence, that’s basically my thing. You can find more experiments like this at mohitaneja.com.

Get In Touch

Have a question or just want to say hi? I'd love to hear from you.

Use this form to send me a message, and I aim to respond within 24 hours.

Get In Touch

Need IT consultation? From simple web development to creating and deploying AI agents on modern infrastructure, I'm here to help.

Use this form to send me a message about your project, and I aim to respond within 24 hours.

© 2025All rights reserved
MohitAneja.com