Gmail + OpenAI: inbox labels that sort themselves
Your inbox isn’t “busy.” It’s noisy. Important threads get buried under promos, receipts, and customer questions, and you end up doing the same sorting work every day.
Marketing managers feel it when campaign replies vanish in the clutter. Founders feel it when billing emails show up late. And support leads? They’re stuck hunting for urgent tickets. This Gmail labeling automation cleans that up automatically, so you can find what matters fast.
This workflow watches new emails in Gmail, uses OpenAI to classify them, and applies the right label immediately. You’ll see exactly how it works, what you need, and where people usually get stuck.
How This Automation Works
The full n8n workflow, from trigger to final output:
n8n Workflow Template: Gmail + OpenAI: inbox labels that sort themselves
flowchart LR
subgraph sg0["Gmail Flow"]
direction LR
n0@{ icon: "mdi:play-circle", form: "rounded", label: "Gmail Trigger", pos: "b", h: 48 }
n1@{ icon: "mdi:robot", form: "rounded", label: "Text Classifier", pos: "b", h: 48 }
n2@{ icon: "mdi:brain", form: "rounded", label: "OpenAI Chat Model", pos: "b", h: 48 }
n3@{ icon: "mdi:message-outline", form: "rounded", label: "High Priority", pos: "b", h: 48 }
n4@{ icon: "mdi:message-outline", form: "rounded", label: "Promotion", pos: "b", h: 48 }
n5@{ icon: "mdi:message-outline", form: "rounded", label: "Finance/Billings", pos: "b", h: 48 }
n6@{ icon: "mdi:message-outline", form: "rounded", label: "Customer Support", pos: "b", h: 48 }
n0 --> n1
n1 --> n3
n1 --> n4
n1 --> n5
n1 --> n6
n2 -.-> n1
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 n1 ai
class n2 aiModel
The Problem: Inbox triage steals time and attention
Email sorting looks harmless until you add it up. You scan subject lines, open messages “just in case,” then move things around so you don’t forget. Meanwhile, the real work waits. A promo email that looks like a partner update. A billing notice that lands in the middle of a thread you meant to answer. A customer asking for help that sits for hours because it didn’t look urgent at first glance. It’s not just time. It’s the constant context switching.
The friction compounds. Here’s where it usually breaks down.
- You reread the same emails multiple times because nothing tells you what deserves attention first.
- Promotional and newsletter clutter pushes urgent client or stakeholder emails out of sight.
- Finance threads end up scattered, so reconciliation becomes a mini project later.
- Support requests hide in the general inbox, which means slower responses and more follow-ups.
The Solution: OpenAI-classified labels applied automatically
This workflow monitors your Gmail inbox for new messages and classifies each email into one of four practical buckets: High Priority, Promotion, Finance/Billing, or Customer Support. The moment an email arrives, n8n captures the subject and body text, sends that content into an OpenAI-powered classifier, and decides which category fits best. Then Gmail applies the matching label automatically, so your inbox organizes itself while you’re doing actual work. No rules to maintain. No “if subject contains…” guessing games. Just consistent labeling you can rely on, even when the wording changes.
The workflow starts with a Gmail trigger that checks for new emails on a set schedule (it’s configured for frequent polling). OpenAI then classifies the message, and n8n routes the email to the correct Gmail labeling action. Finally, the right Gmail label is applied so you can filter instantly and keep your attention on the right threads.
What You Get: Automation vs. Results
| What This Workflow Automates | Results You’ll Get |
|---|---|
|
|
Example: What This Looks Like
Say your inbox gets about 50 new emails a day. If you spend even 30 seconds reading, deciding, and labeling each one, that’s roughly 25 minutes of pure sorting, not counting the times you re-open something to double-check it. With this workflow, your “work” is basically zero: the email arrives, OpenAI classifies it, and Gmail labels it in the background. You skim your labeled views (Priority first), and move on.
What You’ll Need
- n8n instance (try n8n Cloud free)
- Self-hosting option if you prefer (Hostinger works well)
- Gmail to monitor incoming emails and apply labels.
- OpenAI to classify email text into categories.
- OpenAI API key (get it from your OpenAI dashboard)
Skill level: Beginner. You’ll connect Gmail + OpenAI, then paste in your Gmail label IDs once.
Don’t want to set this up yourself? Talk to an automation expert (free 15-minute consultation).
How It Works
New email arrives in Gmail. The Gmail trigger checks your inbox on a schedule (this workflow is set up to check very frequently), and pulls in the message content for processing.
Email text gets classified. n8n sends the subject and body to an OpenAI-powered text classifier (using a chat model behind the scenes) that decides which of the four categories the email belongs to.
The workflow routes to the right label. Based on the category result, n8n follows the matching path so only one Gmail labeling action runs for that email.
Gmail labels the message automatically. The email is tagged as High Priority, Promotion, Finance/Billing, or Customer Support, so you can filter and focus without touching the message.
You can easily modify the category names to match your team’s language, or add a new category (like “HR” or “Vendors”) 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 Gmail trigger to watch for incoming messages and kick off the classification flow.
- Add the Gmail Intake Trigger node to your canvas.
- Credential Required: Connect your gmailOAuth2 credentials.
- Keep Simple set to
false. - In Poll Times, set the schedule to
everyMinuteto check for new emails frequently.
Step 2: Connect Gmail for Labeling Actions
Ensure all Gmail action nodes are ready to apply labels to classified emails.
- Open Label High Urgency and set Operation to
addLabels. - Set Message ID to
{{ $json.id }}in Label High Urgency. - Repeat the same Operation and Message ID settings for Tag Promotions, Mark Finance Items, and Label Support Requests.
- Credential Required: Connect your gmailOAuth2 credentials in Label High Urgency, Tag Promotions, Mark Finance Items, and Label Support Requests.
[YOUR_ID] with real Gmail label IDs before testing, or labels will not be applied.Step 3: Set Up the AI Classification
Configure the classifier and link it to the OpenAI model for categorization.
- Add the Categorize Email Text node after Gmail Intake Trigger.
- Set Input Text to
{{ $json.text }}. - Verify the category list in Categorize Email Text includes:
High Priority,Promotion,Finance/Billing, andCustomer Supportwith their descriptions. - Add OpenAI Conversation Model and set Model to
gpt-5. - Credential Required: Connect your openAiApi credentials in OpenAI Conversation Model.
- Connect OpenAI Conversation Model to Categorize Email Text as the language model (AI sub-connection).
Step 4: Configure the Output Labeling Paths
Route classifications to the correct Gmail labeling actions.
- Connect Categorize Email Text to Label High Urgency.
- Also connect Categorize Email Text to Tag Promotions, Mark Finance Items, and Label Support Requests on separate outputs.
- Confirm label IDs in each node match the intended Gmail labels.
Categorize Email Text outputs to Label High Urgency, Tag Promotions, Mark Finance Items, and Label Support Requests in parallel.
Step 5: Test and Activate Your Workflow
Run a manual test to ensure emails are categorized and labeled correctly, then turn on the workflow for live use.
- Click Execute Workflow and send a test email that matches one of the defined categories.
- Verify Gmail Intake Trigger picks up the email and Categorize Email Text assigns a category.
- Check Gmail to confirm the correct label was applied by Label High Urgency, Tag Promotions, Mark Finance Items, or Label Support Requests.
- Once validated, switch the workflow to Active for continuous classification.
Common Gotchas
- Gmail credentials can expire or need specific permissions. If things break, check the credential status in n8n and re-authenticate the Google account first.
- If you’re polling every minute, Gmail can occasionally return delays or temporary API limits. When labels stop applying, check recent executions in n8n to see if messages were fetched but not updated.
- OpenAI classification is only as good as your category descriptions. If “High Priority” is too vague, you will get weird labels and you’ll be fixing it manually later.
Frequently Asked Questions
About 30 minutes if your Gmail labels are already created.
No. You will connect Gmail and OpenAI, then paste in a few label IDs.
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 usage, which is usually small for simple text classification.
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 you’ll want to do it in two places. Add “Vendors” as a new category in the Categorize Email Text classifier, then create a matching Gmail label and add another Gmail labeling node for that label ID. Most people also tweak the category descriptions so OpenAI understands the boundary between “Finance/Billing” and vendor updates. Once that’s done, it behaves like the built-in four.
Usually it’s expired OAuth access or the wrong Google account connected in n8n. Reconnect the Gmail credential, then rerun one execution and check if the workflow can both read new emails and modify labels. If it can read but can’t label, it’s commonly missing Gmail permissions or the label IDs in the Gmail nodes don’t match your account’s labels.
A lot—most small teams can run this all day without thinking about it. On n8n Cloud, your limit depends on your plan’s monthly executions; self-hosting doesn’t impose an execution cap, but your server still has to keep up. Practically, the bottlenecks are Gmail API limits and how frequently you poll. If you’re getting hundreds of emails a day, increase the polling interval a bit and keep an eye on OpenAI usage.
Often, yes, because this kind of classification-and-routing flow gets fiddly in simpler tools. n8n handles branching logic cleanly, you can self-host for unlimited executions, and it’s easier to control exactly how the OpenAI classification feeds the Gmail labeling actions. Zapier or Make can still work if you only want a basic “label promo emails” setup and don’t care about deeper control. The tradeoff is that costs can climb as volume grows. If you’re unsure, Talk to an automation expert and describe your email volume and categories.
Once your inbox labels itself, you stop treating email like a scavenger hunt. Set it up once, let it run, and keep your attention for the work that actually moves the business.
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.