Classify and label new Gmail emails with OpenAI GPT-4.1 mini
Ready for 3.0Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.
What this workflow does
This AI workflow has 9 nodes and runs on Gmail events. Along the way it connects Gmail and OpenAI.
How it runs
Trigger: On Gmail events.
- Settings (Edit Fields (Set)): sets 6 fields: business_name, openai_model, label_prefix…
- Prepare Email (Code): runs custom JavaScript code
- Classify Email (OpenAI): response (text)
- Parse Classification (Code): runs custom JavaScript code
- Get Gmail Labels (Gmail): get many (label)
- Resolve Labels (Code): runs custom JavaScript code
- Has Label? (If): checks a condition and branches into true / false
- Apply Gmail Label (Gmail): add labels (message)
Services it uses
Before you upgrade to n8n 3.0
Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.
- Still check Gmail Trigger below v1.4 runs as v1.4 (drafts skipped, max emails per poll) (Gmail Trigger).
Nodes used (6)
- Gmail Trigger
n8n-nodes-base.gmailTrigger - Edit Fields (Set)
n8n-nodes-base.set - Code
n8n-nodes-base.code - OpenAI
@n8n/n8n-nodes-langchain.openAi - Gmail
n8n-nodes-base.gmail - If
n8n-nodes-base.if
From the author
Quick Overview This workflow polls Gmail for new messages, uses OpenAI to classify each email into a category and priority with a short summary, and then applies matching Gmail labels (for example, AI/Urgent or AI/Sales Lead) when the labels exist in your…