Gmail + OpenAI: inbox labels applied automatically
Your inbox is probably lying to you. It looks “manageable” until you open it and realize half the threads are in the wrong place, important messages are buried, and you are doing the same sorting work every single day. Gmail labeling automation fixes that.
Marketing managers feel it when client emails disappear under newsletters. Business owners see it when finance threads mix with sales conversations. And busy operators end up triaging at night. This workflow auto-applies the right Gmail label the moment an email arrives, so you stay organized without living in your inbox.
Below, you’ll see how the workflow runs in n8n, what it automates end-to-end, and how to tailor the categories (Work, Finance, Newsletter, and more) to match your real world.
How This Automation Works
The full n8n workflow, from trigger to final output:
n8n Workflow Template: Gmail + OpenAI: inbox labels applied automatically
flowchart LR
subgraph sg0["Gmail Intake Flow"]
direction LR
n0@{ icon: "mdi:play-circle", form: "rounded", label: "Gmail Intake Trigger", pos: "b", h: 48 }
n1@{ icon: "mdi:swap-horizontal", form: "rounded", label: "Label Presence Filter", pos: "b", h: 48 }
n2@{ icon: "mdi:robot", form: "rounded", label: "AI Labeling Agent", pos: "b", h: 48 }
n3@{ icon: "mdi:brain", form: "rounded", label: "OpenAI Chat Engine", pos: "b", h: 48 }
n4@{ icon: "mdi:robot", form: "rounded", label: "Structured Result Parser", pos: "b", h: 48 }
n5@{ icon: "mdi:swap-horizontal", form: "rounded", label: "Route By Label", pos: "b", h: 48 }
n6@{ icon: "mdi:message-outline", form: "rounded", label: "Apply Work Label", pos: "b", h: 48 }
n7@{ icon: "mdi:message-outline", form: "rounded", label: "Apply Personal Label", pos: "b", h: 48 }
n8@{ icon: "mdi:message-outline", form: "rounded", label: "Apply Finance Label", pos: "b", h: 48 }
n9@{ icon: "mdi:message-outline", form: "rounded", label: "Apply Shopping Label", pos: "b", h: 48 }
n10@{ icon: "mdi:message-outline", form: "rounded", label: "Apply Travel Label", pos: "b", h: 48 }
n11@{ icon: "mdi:message-outline", form: "rounded", label: "Apply Newsletter Label", pos: "b", h: 48 }
n12@{ icon: "mdi:message-outline", form: "rounded", label: "Apply Other Label", pos: "b", h: 48 }
n5 --> n6
n5 --> n7
n5 --> n8
n5 --> n9
n5 --> n10
n5 --> n11
n5 --> n12
n0 --> n1
n3 -.-> n2
n1 --> n2
n2 --> n5
n4 -.-> n2
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n0 trigger
class n2,n4 ai
class n3 aiModel
class n1,n5 decision
The Problem: Inbox triage steals your best hours
Labeling email sounds small until you add it up. You read a message, decide what it is, remember your label names, apply one (or two), then move on. Repeat that 50 times and you’ve burned a chunk of your morning on work that doesn’t move anything forward. It also creates “decision fatigue,” which is a fancy way of saying your brain is tired before the important work starts. And when you skip labeling for a day or two, your inbox stops being a system and turns into a pile.
It adds up fast. Here’s where it breaks down in real teams and solo businesses.
- You end up re-reading the same email later because it wasn’t labeled and you couldn’t find it quickly.
- Client and internal threads blend together, which means slower replies and more context switching.
- Finance emails get missed because they look like “just another notification” in the main inbox.
- Newsletters and promos quietly take over, so the inbox feels busy even when nothing is urgent.
The Solution: New Gmail emails labeled by OpenAI
This n8n workflow watches your Gmail inbox for new messages, checks if they already have labels, and only processes the ones that still need sorting. Then it sends the email content to an AI Agent powered by GPT-4o mini, which decides which category fits best (like Work, Personal, Finance, Shopping, Travel, Newsletter, or Other). The AI response is formatted into clean structured data, so it stays predictable instead of “creative.” Finally, the workflow routes the email down the correct path and applies the matching Gmail label automatically. You don’t have to drag messages around, and you don’t have to remember to keep things tidy. It just happens.
The workflow starts when a new Gmail email hits your inbox. From there, a label-presence filter prevents double-work, and the AI Agent chooses a label based on your category rules. The Switch node routes the message, then a Gmail action applies the correct label to the original email.
What You Get: Automation vs. Results
| What This Workflow Automates | Results You’ll Get |
|---|---|
|
|
Example: What This Looks Like
Say you get about 60 emails a day and you spend maybe 30 seconds deciding and applying a label. That’s roughly 30 minutes daily, or about 2.5 hours a week, just on sorting. With this workflow, the “work” becomes near zero: emails are labeled as they arrive, and you only touch the handful that truly need a human judgment call. Even if you still review labels for a minute or two, you get a big chunk of your week back.
What You’ll Need
- n8n instance (try n8n Cloud free)
- Self-hosting option if you prefer (Hostinger works well)
- Gmail for receiving emails and applying labels
- OpenAI to categorize emails with GPT-4o mini
- OpenAI API key (get it from the OpenAI dashboard)
Skill level: Beginner. You’ll connect accounts, create labels in Gmail, and adjust a prompt.
Don’t want to set this up yourself? Talk to an automation expert (free 15-minute consultation).
How It Works
A new email arrives in Gmail. The Gmail Trigger kicks off the workflow as soon as a message lands, so organization happens while your inbox is still fresh.
Already-labeled messages get ignored. A filter checks label presence and skips anything that’s already been handled. This small detail matters, because it prevents loops and accidental relabeling when you reply or archive.
OpenAI categorizes the email. The AI Agent (using GPT-4o mini) reads the email content and chooses one category from your predefined list. A structured output parser then forces that choice into clean JSON so the next step can reliably route it.
The correct Gmail label is applied. A Switch node sends the email down the Work, Personal, Finance, Shopping, Travel, Newsletter, or Other path, then the matching Gmail node applies the label to the original message.
You can easily modify the category list to match your business labels based on your needs. See the full implementation guide below for customization options.
Step-by-Step Implementation Guide
Step 1: Configure the Gmail Trigger
Set up the workflow to listen for new Gmail messages and pass them into the labeling pipeline.
- Add and open Gmail Intake Trigger.
- Credential Required: Connect your gmailOAuth2 credentials.
- Set Poll Times to
everyMinute(already configured in the node). - Keep Simple set to
falseto retain full email payloads.
Step 2: Connect Gmail Actions
All label-application nodes use Gmail actions to add category labels to the triggered email.
- Open each Gmail action node that applies labels (7 total): Apply Work Label, Apply Personal Label, Apply Finance Label, Apply Shopping Label, Apply Travel Label, Apply Newsletter Label, and Apply Other Label.
- Credential Required: Connect your gmailOAuth2 credentials on all Gmail action nodes.
- Confirm Operation is set to
addLabels. - Verify Message ID uses the expression
={{ $('Gmail Intake Trigger').item.json.id }}to label the correct email.
Step 3: Set Up the Label Presence Filter
Filter out emails that already contain labels so only unlabeled messages are processed by the AI.
- Open Label Presence Filter.
- Set the condition to use Left Value
={{ $json.labelIds[0] }}. - Configure the rule as String notContains with Right Value
Label. - Ensure the node is connected from Gmail Intake Trigger to AI Labeling Agent exactly as in the execution flow.
Step 4: Set Up AI Classification
Configure the AI stack to analyze email content and output a structured label for routing.
- Open OpenAI Chat Engine and confirm the Model is set to
gpt-4o-mini. - Credential Required: Connect your openAiApi credentials in OpenAI Chat Engine.
- Open AI Labeling Agent and set Text to
=Topic: {{ $json.subject }} Description: {{ $json.text }} Sender: {{ $json.from.text }}. - Keep Prompt Type set to
defineand ensure Has Output Parser is enabled. - Open Structured Result Parser and set JSON Schema Example to
{ "email_label": "business" }. - Ensure OpenAI Chat Engine is connected to AI Labeling Agent as the language model, and Structured Result Parser is connected as the output parser.
Step 5: Configure Routing and Label Application
Route the AI output to the correct Gmail label node using a switch based on the structured label.
- Open Route By Label and confirm each rule evaluates
={{ $json.output.email_label }}. - Verify output keys exist for
Work,Personal,Finance,Shopping,Travel,Newsletters, andOthers. - Ensure Route By Label outputs to the corresponding Gmail label nodes for each category.
- Confirm the execution flow: Gmail Intake Trigger → Label Presence Filter → AI Labeling Agent → Route By Label → Gmail label node.
Step 6: Test and Activate Your Workflow
Validate the end-to-end flow with a real email and then activate for production use.
- Click Execute Workflow and send a test email to the monitored inbox.
- Check that Label Presence Filter passes the email and AI Labeling Agent returns
output.email_label. - Confirm the correct Gmail label node (e.g., Apply Work Label) runs and applies the label.
- When successful, toggle the workflow to Active for live operation.
Common Gotchas
- Gmail credentials can expire or need specific permissions. If things break, check the n8n Credentials panel and your Google account security alerts first.
- If you tune the Gmail trigger to run very frequently, you may hit rate limits or see occasional delays. If emails are missed, widen the polling interval and confirm your Gmail Trigger query settings.
- OpenAI output can drift if the prompt is vague. Be strict about “choose exactly one label from this list,” or you’ll get categories that don’t match your pre-created Gmail labels.
Frequently Asked Questions
About 20 minutes if your Gmail labels are already created.
No. You’ll connect Gmail and OpenAI, then edit a few category rules. The hardest part is naming labels consistently.
Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in OpenAI API costs, which are usually just a few dollars a month for typical inbox volumes.
Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.
Yes, but your Gmail labels must exist first. Update the AI Agent prompt to include your exact label names, then add matching rules in the Route By Label (Switch) node so each category routes to the right Gmail “apply label” action. Common tweaks are adding a “Leads” label, splitting “Work” into client-specific labels, or creating a “Vendor” bucket for tools and subscriptions.
Most of the time it’s an expired Google authorization in n8n. Reconnect the Gmail credential, then re-run one test email. Also check that the Google account has access to the mailbox you’re monitoring (especially with shared inboxes), and confirm you didn’t change password or security settings recently.
A lot. In practice, most small teams can label hundreds of emails a day without issues, and self-hosting removes execution caps (your server becomes the limit).
For AI-based labeling, n8n is usually the better fit because you can enforce structured output, route with a Switch across many categories, and keep scaling costs under control if you self-host. Zapier and Make can do it, but multi-branch logic tends to get messy, and AI steps can get expensive as volume grows. If you only want a simple “if subject contains X, apply label Y” rule, those tools are totally fine. If you want OpenAI to decide the label, n8n is honestly easier to maintain long-term. Talk to an automation expert if you want help picking the right stack.
Once your inbox labels itself, email stops feeling like a surprise attack. Set it up once, then spend your attention on work that actually pays you back.
Need Help Setting This Up?
Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.