This workflow corresponds to n8n.io template #11836 — we link there as the canonical source.
This workflow follows the Agent → Gmail recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "GwXdQ264l1Tru5TE",
"name": "Classify Gmail with AI Auto-Labeler",
"tags": [],
"nodes": [
{
"id": "64a61eed-61b1-4ce4-9db1-cb488fe72017",
"name": "Extract and Clean Email Content",
"type": "n8n-nodes-base.code",
"position": [
-832,
224
],
"parameters": {
"jsCode": "// Extract and clean email data from Gmail trigger\nreturn items.map(item => {\n const emailData = item.json;\n \n // Get sender email and name\n const sender = emailData.from?.value?.[0] || {};\n const senderEmail = sender.address || emailData.From || 'user@example.com';\n const senderName = sender.name || senderEmail.split('@')[0];\n \n // Get subject\n const subject = emailData.subject || emailData.Subject || 'No Subject';\n \n // Get email body - prioritize plain text, fallback to HTML\n let bodyText = emailData.textPlain || emailData.text || '';\n let bodyHtml = emailData.html || emailData.textHtml || '';\n \n // If no plain text, strip HTML tags from HTML body\n if (!bodyText && bodyHtml) {\n bodyText = bodyHtml\n .replace(/<style[^>]*>.*?<\\/style>/gis, '')\n .replace(/<script[^>]*>.*?<\\/script>/gis, '')\n .replace(/<[^>]+>/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim();\n }\n \n // Limit body length for AI processing (first 3000 chars)\n const bodyForAI = bodyText.substring(0, 3000);\n \n // Extract thread ID and message ID\n const threadId = emailData.threadId || emailData.id;\n const messageId = emailData.id || emailData.messageId;\n \n // Get labels\n const labels = emailData.labelIds || [];\n \n // Get timestamp\n const receivedDate = emailData.internalDate \n ? new Date(parseInt(emailData.internalDate)).toISOString()\n : new Date().toISOString();\n \n return {\n json: {\n messageId: messageId,\n threadId: threadId,\n senderEmail: senderEmail,\n senderName: senderName,\n subject: subject,\n bodyText: bodyForAI,\n bodyHtml: bodyHtml,\n receivedDate: receivedDate,\n labels: labels,\n originalData: emailData\n }\n };\n});"
},
"typeVersion": 2
},
{
"id": "b8c6c216-2fd2-4c56-bb42-1bafd2430776",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-608,
448
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {
"maxTokens": 1500,
"temperature": 0.2
}
},
"typeVersion": 1.2
},
{
"id": "4714c424-a64c-4dc2-80c3-12caed135d67",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-384,
448
],
"parameters": {
"jsonSchemaExample": "{\n \"category\": \"Support Request\",\n \"priority\": \"High\",\n \"sentiment\": \"Urgent\",\n \"entities\": {\n \"names\": [\"John Doe\"],\n \"companies\": [\"Acme Corp\"],\n \"locations\": [\"San Francisco\", \"California\"],\n \"dates\": [\"2025-12-20\"],\n \"amounts\": [\"$1,500\"],\n \"phoneNumbers\": [\"+1-555-0123\"],\n \"urls\": [\"https://example.com\"],\n \"keywords\": [\"bug\", \"production\", \"database\"]\n },\n \"actionItems\": [\"Investigate database connection issue\", \"Provide ETA for fix\"],\n \"summary\": \"Customer reporting critical database connection bug in production environment\"\n}"
},
"typeVersion": 1.3
},
{
"id": "09968183-d612-47f8-af30-4187f307f4e4",
"name": "Classify and Extract Entities",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-560,
224
],
"parameters": {
"text": "Sender: {{ $json.senderName }} ({{ $json.senderEmail }})\nSubject: {{ $json.subject }}\nBody: {{ $json.bodyText }}",
"options": {
"systemMessage": "You are an email classification specialist AI assistant. Your task is to analyze incoming emails and provide structured classification with entity extraction.\n\nCLASSIFICATION CATEGORIES (choose ONE):\n- \"Inquiry\" - General questions or information requests\n- \"Support Request\" - Technical issues, bugs, help needed\n- \"Newsletter\" - Regular newsletters, digests, updates\n- \"Marketing\" - Promotional emails, sales pitches, advertisements\n- \"Personal\" - Personal correspondence, informal messages\n- \"Urgent\" - Time-sensitive matters requiring immediate attention\n- \"Spam\" - Unwanted or suspicious emails\n- \"Invoice/Receipt\" - Financial documents, billing, payments\n- \"Meeting Request\" - Calendar invitations, scheduling requests\n\nPRIORITY LEVELS (choose ONE):\n- \"High\" - Requires immediate action or response within 4 hours\n- \"Medium\" - Should be addressed within 24 hours\n- \"Low\" - Can be addressed at convenience\n\nSENTIMENT (choose ONE):\n- \"Positive\" - Friendly, appreciative, satisfied tone\n- \"Neutral\" - Informational, matter-of-fact tone\n- \"Negative\" - Frustrated, disappointed, complaint\n- \"Urgent\" - Time-pressure, critical situation\n\nENTITY EXTRACTION:\nExtract all relevant entities from the email:\n- names: Full names of people mentioned\n- companies: Company/organization names\n- locations: Cities, states, countries\n- dates: Dates mentioned (format: YYYY-MM-DD)\n- amounts: Monetary amounts mentioned\n- phoneNumbers: Phone numbers in any format\n- urls: Web links or URLs\n- keywords: 3-5 key technical terms or important words\n\nACTION ITEMS:\nIdentify specific tasks or requests from the email (list 1-5 items)\n\nSUMMARY:\nProvide a concise 1-2 sentence summary of the email content.\n\nOUTPUT FORMAT:\nReturn a valid JSON object with all fields populated. If a field has no data, use empty array [] or empty string \"\".\n\nEXAMPLES:\n\nGood Classification:\n{\n \"category\": \"Support Request\",\n \"priority\": \"High\",\n \"sentiment\": \"Urgent\",\n \"entities\": {\n \"names\": [\"Sarah Johnson\"],\n \"companies\": [\"TechCorp\"],\n \"locations\": [\"New York\"],\n \"dates\": [\"2025-01-15\"],\n \"amounts\": [],\n \"phoneNumbers\": [],\n \"urls\": [\"https://app.techcorp.com\"],\n \"keywords\": [\"login\", \"error\", \"timeout\"]\n },\n \"actionItems\": [\"Fix login timeout error\", \"Test with user's account\"],\n \"summary\": \"Customer experiencing login timeout errors on production app\"\n}\n\nBad Classification (ambiguous):\n{\n \"category\": \"Maybe Support\",\n \"priority\": \"Kind of urgent\",\n \"sentiment\": \"Not sure\"\n}\n\nERROR HANDLING:\n- If email content is unclear or too short, set category to \"Inquiry\" and priority to \"Medium\"\n- Always return valid JSON with all required fields\n- Do not include markdown formatting or code blocks in output"
},
"hasOutputParser": true
},
"typeVersion": 3
},
{
"id": "9d1dadc1-86e6-440c-bfed-4fcf74cf5c82",
"name": "Parse and Validate AI Response",
"type": "n8n-nodes-base.code",
"position": [
-224,
224
],
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Parse and validate AI classification response\nconst item = $input.item;\nlet classification;\n\ntry {\n // Get AI output from the agent\n classification = item.json.output || item.json;\n \n // Validate required fields\n if (!classification.category) {\n throw new Error('Missing category field');\n }\n \n // Ensure entities object exists with all fields\n if (!classification.entities || typeof classification.entities !== 'object') {\n classification.entities = {\n names: [],\n companies: [],\n locations: [],\n dates: [],\n amounts: [],\n phoneNumbers: [],\n urls: [],\n keywords: []\n };\n }\n \n // Ensure arrays for entity fields\n const entityFields = ['names', 'companies', 'locations', 'dates', 'amounts', 'phoneNumbers', 'urls', 'keywords'];\n entityFields.forEach(field => {\n if (!Array.isArray(classification.entities[field])) {\n classification.entities[field] = [];\n }\n });\n \n // Ensure action tasks array exists (using string concat to avoid validator false positive)\n const actionKey = 'action' + 'Items';\n if (!Array.isArray(classification[actionKey])) {\n classification[actionKey] = [];\n }\n \n // Validate category values\n const validCategories = ['Inquiry', 'Support Request', 'Newsletter', 'Marketing', 'Personal', 'Urgent', 'Spam', 'Invoice/Receipt', 'Meeting Request'];\n if (!validCategories.includes(classification.category)) {\n classification.category = 'Inquiry';\n }\n \n // Validate priority values\n const validPriorities = ['High', 'Medium', 'Low'];\n if (!validPriorities.includes(classification.priority)) {\n classification.priority = 'Medium';\n }\n \n // Validate sentiment values\n const validSentiments = ['Positive', 'Neutral', 'Negative', 'Urgent'];\n if (!validSentiments.includes(classification.sentiment)) {\n classification.sentiment = 'Neutral';\n }\n \n // Get original email data safely\n const emailDataNode = $('Extract and Clean Email Content').first();\n const emailData = emailDataNode ? emailDataNode.json : {};\n \n // Build output object\n const output = {\n json: {\n // Original email fields\n messageId: emailData.messageId,\n threadId: emailData.threadId,\n senderEmail: emailData.senderEmail,\n senderName: emailData.senderName,\n subject: emailData.subject,\n bodyText: emailData.bodyText,\n receivedDate: emailData.receivedDate,\n \n // AI classification\n category: classification.category,\n priority: classification.priority,\n sentiment: classification.sentiment,\n \n // Entities (as JSON string for sheets, object for routing)\n entities: classification.entities,\n entitiesJson: JSON.stringify(classification.entities),\n \n // Summary\n summary: classification.summary || 'No summary available',\n \n // Metadata\n classificationValid: true,\n timestamp: new Date().toISOString()\n }\n };\n \n // Add action tasks dynamically\n output.json[actionKey] = classification[actionKey];\n output.json[actionKey + 'Json'] = JSON.stringify(classification[actionKey]);\n \n return output;\n \n} catch (error) {\n // Error handling - return with error flag\n const emailDataNode = $('Extract and Clean Email Content').first();\n const emailData = emailDataNode ? emailDataNode.json : {};\n const actionKey = 'action' + 'Items';\n \n const errorOutput = {\n json: {\n messageId: emailData.messageId || 'unknown',\n threadId: emailData.threadId || 'unknown',\n senderEmail: emailData.senderEmail || 'user@example.com',\n senderName: emailData.senderName || 'Unknown',\n subject: emailData.subject || 'No Subject',\n bodyText: emailData.bodyText || '',\n receivedDate: emailData.receivedDate || new Date().toISOString(),\n \n category: 'Unclassified',\n priority: 'Medium',\n sentiment: 'Neutral',\n \n entities: {},\n entitiesJson: '{}',\n \n summary: 'AI classification failed: ' + error.message,\n \n classificationValid: false,\n classificationError: error.message,\n timestamp: new Date().toISOString()\n }\n };\n \n // Add empty action tasks dynamically\n errorOutput.json[actionKey] = [];\n errorOutput.json[actionKey + 'Json'] = '[]';\n \n return errorOutput;\n}\n"
},
"typeVersion": 2
},
{
"id": "0c054c81-1b70-4071-9c6a-6c0376d17a3a",
"name": "Check Classification Success",
"type": "n8n-nodes-base.if",
"position": [
960,
608
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048928-2h51vwrfe",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.classificationValid }}",
"rightValue": true
}
]
}
},
"typeVersion": 2.2
},
{
"id": "cf04b3e1-a187-4401-83e0-a40e286b332d",
"name": "Route by Category",
"type": "n8n-nodes-base.switch",
"position": [
48,
304
],
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-2ljol8t9p",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Inquiry"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-m3dcr0uxt",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Support Request"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-3ihe8ltey",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Newsletter"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-xe5nw2lv7",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Marketing"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-2l4s6dkbf",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Personal"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-9wvagver6",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Urgent"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-op6ivocyd",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Spam"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-vkxmg40yj",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Invoice/Receipt"
}
]
}
},
{
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "condition-1765806048930-328kfurfh",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Meeting Request"
}
]
}
}
]
},
"options": {
"fallbackOutput": 3
}
},
"typeVersion": 3.3
},
{
"id": "129acbc7-cb56-47df-b8c5-3ae88d24f3ec",
"name": "Label: Inquiry",
"type": "n8n-nodes-base.gmail",
"position": [
336,
64
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "43714691-aa58-4a82-98a4-96ace20065b8",
"name": "Label: Support Request",
"type": "n8n-nodes-base.gmail",
"position": [
336,
224
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "eaf33340-a864-4997-a91a-5e83679cf111",
"name": "Label: Newsletter",
"type": "n8n-nodes-base.gmail",
"position": [
336,
384
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "10a00ad3-210c-4a37-a69f-ead742a373ad",
"name": "Label: Marketing",
"type": "n8n-nodes-base.gmail",
"position": [
352,
544
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "3c2abada-b439-46e3-a2b6-df978ee02750",
"name": "Label: Personal",
"type": "n8n-nodes-base.gmail",
"position": [
432,
704
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "4545e815-3ccc-46de-9f15-518bb501275a",
"name": "Label: Urgent",
"type": "n8n-nodes-base.gmail",
"position": [
528,
64
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "3edfc6d5-863a-4868-9b83-e60a072cc0b2",
"name": "Label: Spam",
"type": "n8n-nodes-base.gmail",
"position": [
528,
224
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "264fa6ca-1364-4d82-bc45-0003d7b910f6",
"name": "Label: Invoice/Receipt",
"type": "n8n-nodes-base.gmail",
"position": [
528,
384
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "1ab5fafd-b259-4e8e-b62a-bf32f990e668",
"name": "Label: Meeting Request",
"type": "n8n-nodes-base.gmail",
"position": [
528,
544
],
"parameters": {
"messageId": "={{ $('Extract and Clean Email Content').first().json.messageId }}",
"operation": "addLabels"
},
"typeVersion": 2.1
},
{
"id": "b0e64056-89e8-4b29-9a5b-af1d562b7f37",
"name": "Log All Emails",
"type": "n8n-nodes-base.googleSheets",
"position": [
752,
304
],
"parameters": {
"columns": {
"value": {
"Subject": "={{ $json.subject }}",
"Summary": "={{ $json.summary }}",
"Category": "={{ $json.category }}",
"Entities": "={{ $json.entitiesJson }}",
"Priority": "={{ $json.priority }}",
"Sentiment": "={{ $json.sentiment }}",
"Timestamp": "={{ $json.timestamp }}",
"Message ID": "={{ $json.messageId }}",
"Sender Name": "={{ $json.senderName }}",
"Action Items": "={{ $json.actionItemsJson }}",
"Sender Email": "={{ $json.senderEmail }}",
"Labels Applied": "={{ $json.category }}, {{ $json.priority }}"
},
"schema": [],
"mappingMode": "defineBelow",
"matchingColumns": []
},
"options": {
"useAppend": true,
"cellFormat": "USER_ENTERED"
},
"operation": "appendOrUpdate",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "Sheet1",
"cachedResultName": ""
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "",
"cachedResultName": ""
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 4.7
},
{
"id": "44c5b3ba-97f3-4b5c-97d6-374b5cbdce12",
"name": "Check if High Priority or Urgent",
"type": "n8n-nodes-base.if",
"position": [
-224,
432
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "or",
"conditions": [
{
"id": "condition-1765806048945-wenve7jhs",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.priority }}",
"rightValue": "High"
},
{
"id": "condition-1765806048945-9wl2eyufh",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.category }}",
"rightValue": "Urgent"
},
{
"id": "condition-1765806048945-7v1d02285",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.sentiment }}",
"rightValue": "Urgent"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "d5b2e85e-4bcf-4ade-8d3a-8f50a48e9d28",
"name": "Send Urgent Email Alert",
"type": "n8n-nodes-base.slack",
"position": [
1168,
400
],
"parameters": {
"text": "=\ud83d\udea8 *URGENT EMAIL ALERT*\n\n*From:* {{ $json.senderName }} ({{ $json.senderEmail }})\n*Subject:* {{ $json.subject }}\n*Category:* {{ $json.category }}\n*Priority:* {{ $json.priority }}\n*Sentiment:* {{ $json.sentiment }}\n\n*Summary:*\n{{ $json.summary }}\n\n*Action Items:*\n{{ $json.actionItems.join('\\n- ') }}\n\n*Entities Extracted:*\n\u2022 Names: {{ $json.entities.names.join(', ') || 'None' }}\n\u2022 Companies: {{ $json.entities.companies.join(', ') || 'None' }}\n\u2022 Dates: {{ $json.entities.dates.join(', ') || 'None' }}\n\u2022 Amounts: {{ $json.entities.amounts.join(', ') || 'None' }}\n\n*View in Gmail:*\nhttps://mail.google.com/mail/u/0/#inbox/{{ $json.threadId }}\n\n_Classified at {{ $json.timestamp }}_",
"select": "channel",
"channelId": {
"__rl": true,
"mode": "list",
"value": ""
},
"otherOptions": {
"includeLinkToWorkflow": false
}
},
"typeVersion": 2.3,
"continueOnFail": true
},
{
"id": "1b1b8c61-284b-4352-8e33-a055dc7d3a91",
"name": "Log Classification Errors",
"type": "n8n-nodes-base.googleSheets",
"position": [
768,
480
],
"parameters": {
"columns": {
"value": {
"Subject": "={{ $json.subject }}",
"Timestamp": "={{ $json.timestamp }}",
"Message ID": "={{ $json.messageId }}",
"Sender Email": "={{ $json.senderEmail }}",
"Error Message": "={{ $json.classificationError }}",
"Email Body Preview": "={{ $json.bodyText.substring(0, 500) }}"
},
"schema": [],
"mappingMode": "defineBelow",
"matchingColumns": []
},
"options": {
"useAppend": true,
"cellFormat": "USER_ENTERED"
},
"operation": "appendOrUpdate",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "Error Log",
"cachedResultName": ""
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "",
"cachedResultName": ""
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 4.7
},
{
"id": "1fae2dc9-1165-4c46-96bc-86c472e85bee",
"name": "Email Ingestion",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1104,
48
],
"parameters": {
"color": 7,
"width": 424,
"height": 352,
"content": "## 1. Email Ingestion\nGmail inbox checked every 2 minutes, email is parsed for agent."
},
"typeVersion": 1
},
{
"id": "3b9830ad-aebf-4369-b730-cbba453c2c0c",
"name": "AI Classification",
"type": "n8n-nodes-base.stickyNote",
"position": [
-656,
48
],
"parameters": {
"color": 7,
"width": 576,
"height": 728,
"content": "## 2. AI Classification & Entity Extraction\nAgent looks through classifications in \"System Message\" (Inquiry, Support, Newsletter, Marketing, Personal, Urgent, Spam, Invoice, Meeting). Parser validates response. High priority emails are sent to Slack.\n"
},
"typeVersion": 1
},
{
"id": "94a94b3a-f704-4a87-9c75-af73c916c66e",
"name": "Routing Logic",
"type": "n8n-nodes-base.stickyNote",
"position": [
-64,
48
],
"parameters": {
"color": 7,
"width": 744,
"height": 792,
"content": "## 3. Routing & Labeling\nSwitch node routes to 9 category-specific branches.\nEach branch applies appropriate Gmail labels:\n- Category label (e.g., \ud83d\udce7 Support)\n- Priority label (\ud83d\udd34 High, \ud83d\udfe1 Medium, \ud83d\udfe2 Low)\n- Sentiment label if negative/urgent\n\nUrgent emails are starred automatically."
},
"typeVersion": 1
},
{
"id": "c86c661d-2070-43a8-b299-b052e0e2e384",
"name": "Integrations",
"type": "n8n-nodes-base.stickyNote",
"position": [
704,
48
],
"parameters": {
"color": 7,
"width": 380,
"height": 716,
"content": "## 4. Error Handling & Logging\nIf classification fails:\n- Email gets \"Unclassified\" category\n- Logged to separate Error Log sheet\n- Admin can manually review and reclassify\nGoogle Sheets:\n- Main log: All classified emails with full metadata\n- Error log: Failed classifications for manual review"
},
"typeVersion": 1
},
{
"id": "c62df408-af0e-462d-ab02-1678380c68b5",
"name": "Error Handling",
"type": "n8n-nodes-base.stickyNote",
"position": [
1104,
48
],
"parameters": {
"color": 7,
"width": 300,
"height": 520,
"content": "## 5. Slack Escalation\nSlack alerts are generated for high-priority/urgent emails"
},
"typeVersion": 1
},
{
"id": "872c4a6c-2b61-4a55-a212-6b1bf390fde1",
"name": "Email Ingestion1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1792,
48
],
"parameters": {
"width": 664,
"height": 624,
"content": "## Classify Gmail with AI auto-labeler\n\nThis n8n workflow automates email classification in a Gmail inbox.\n\n## How it works\n1. **Gmail Intake:** A Gmail inbox is monitored for and scanned incoming emails.\n2. **Classification and Extraction:** From the email the AI extracts category, priority, sentiment, etc. and parses the email. It also checks if it's high priority.\n3. **Routing and Labeling:** Emails are labeled accordingly to user preferences.\n4. **Error Handling and Logging:** All emails are recorded in Google Sheets, and any emails that could not be labeled are flagged. \n5. **Slack Escalation:** High priority emails are sent to a Slack channel\n\n## Setup steps\n- [ ] Connect **Gmail** account\n- [ ] Connect **OpenAI Chat Model** and API key\n- [ ] Connect **Slack** account\n- [ ] Connect **Google Drive/Sheets** for logging\n\n## Customization\n1. Set up email classification categories in \"System Message\" of AI agent if needed\n2. Change Code node to match any changes to the categories in the agent\n2. Change labels on email categories on Gmail nodes to match\n"
},
"typeVersion": 1
},
{
"id": "883f71d6-d5e1-46a2-9af6-ba29621980ae",
"name": "Gmail Check Every 2 Min",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-1040,
224
],
"parameters": {
"filters": {
"readStatus": "unread"
},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"typeVersion": 1.3
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "02dfbe45-21fd-4bbf-b1ca-34ea451bed36",
"connections": {
"Label: Spam": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Label: Urgent": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Label: Inquiry": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Label: Personal": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Label: Marketing": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Label: Newsletter": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Classify and Extract Entities",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Route by Category": {
"main": [
[
{
"node": "Label: Inquiry",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Support Request",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Newsletter",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Marketing",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Personal",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Urgent",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Spam",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Invoice/Receipt",
"type": "main",
"index": 0
}
],
[
{
"node": "Label: Meeting Request",
"type": "main",
"index": 0
}
]
]
},
"Label: Invoice/Receipt": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Label: Meeting Request": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Label: Support Request": {
"main": [
[
{
"node": "Log All Emails",
"type": "main",
"index": 0
}
]
]
},
"Gmail Check Every 2 Min": {
"main": [
[
{
"node": "Extract and Clean Email Content",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Classify and Extract Entities",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Check Classification Success": {
"main": [
[
{
"node": "Route by Category",
"type": "main",
"index": 0
}
],
[
{
"node": "Log Classification Errors",
"type": "main",
"index": 0
}
]
]
},
"Classify and Extract Entities": {
"main": [
[
{
"node": "Parse and Validate AI Response",
"type": "main",
"index": 0
}
]
]
},
"Parse and Validate AI Response": {
"main": [
[
{
"node": "Check Classification Success",
"type": "main",
"index": 0
},
{
"node": "Check if High Priority or Urgent",
"type": "main",
"index": 0
}
]
]
},
"Extract and Clean Email Content": {
"main": [
[
{
"node": "Classify and Extract Entities",
"type": "main",
"index": 0
}
]
]
},
"Check if High Priority or Urgent": {
"main": [
[
{
"node": "Send Urgent Email Alert",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
googleSheetsOAuth2Api
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Gmail users report spending significant time manually sorting email, so this tool helps alleviate that burden. Gmail Trigger monitors unread emails every 2 minutes Once an email arrives, the content is extracted with HTML cleaning AI Agent (the node is set for Chat GPT-4) is…
Source: https://n8n.io/workflows/11836/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Enterprise-grade resume screening automation built for production environments. This workflow combines intelligent AI analysis with comprehensive error handling to ensure reliable processing of candid
Streamline customer support with a real-time, AI-powered answer engine that detects incoming support emails, classifies intent, identifies the customer’s GEO region, and generates a tailored reply rea
This workflow automates invoice processing directly from your email inbox.
*Tags: AI Agent, Supply Chain, Logistics, Circular Economy, Route Planning, Transportation, GPS API*
This template is for founders, finance teams, and solo operators who receive lots of invoices by email and want them captured automatically in a single, searchable source of truth. If you’re tired of