This workflow corresponds to n8n.io template #7839 — we link there as the canonical source.
This workflow follows the Error Trigger → 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 →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "a75f0c4e-9b1e-4f76-81a7-903707c0548a",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-1376,
528
],
"parameters": {
"simple": false,
"filters": {
"labelIds": [
"INBOX"
],
"readStatus": "unread"
},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "53354083-ac12-458b-a234-773b6ba38b7e",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-704,
464
],
"parameters": {
"color": 5,
"width": 512,
"height": 224,
"content": "## Label Mail"
},
"typeVersion": 1
},
{
"id": "7e47b472-0331-4bc5-bba8-bda3f42b4e9e",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-704,
720
],
"parameters": {
"color": 5,
"width": 512,
"height": 224,
"content": "## Label Mail"
},
"typeVersion": 1
},
{
"id": "b0c7e415-5528-4387-a029-60486c04b92e",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-704,
976
],
"parameters": {
"color": 5,
"width": 512,
"height": 224,
"content": "## Label Mail"
},
"typeVersion": 1
},
{
"id": "da115060-3031-4b1c-8a10-5b0e79334817",
"name": "compliants label",
"type": "n8n-nodes-base.gmail",
"position": [
-608,
528
],
"parameters": {
"labelIds": [
"Label_2738167986001899947"
],
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "189ecb15-a0dd-427a-9985-f234bcc45ca8",
"name": "info label",
"type": "n8n-nodes-base.gmail",
"position": [
-608,
784
],
"parameters": {
"labelIds": [
"Label_8719801794646735130"
],
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "18a8ab55-c133-4477-92ef-3e8c32ef97c4",
"name": "other label",
"type": "n8n-nodes-base.gmail",
"position": [
-608,
1040
],
"parameters": {
"labelIds": [
"UNREAD"
],
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "346a2604-416c-4064-9cb1-173d81cd961d",
"name": "Mail Classifier",
"type": "@n8n/n8n-nodes-langchain.textClassifier",
"position": [
-1184,
480
],
"parameters": {
"options": {
"fallback": "other"
},
"inputText": "=Subject: {{ $('Gmail Trigger').item.json.subject }}\nText: {{ $('Gmail Trigger').item.json.text }}",
"categories": {
"categories": [
{
"category": "support",
"description": "Emails requesting help, troubleshooting, or guidance regarding products or services. Includes technical issues, user problems, or requests for assistance."
},
{
"category": "sales",
"description": "Emails expressing interest in products or services, requests for quotes, proposals, or meetings with the sales team. Potential client inquiries fall here."
},
{
"category": "complaints",
"description": "Emails expressing dissatisfaction, reporting errors, or filing complaints. Includes customer grievances or urgent service issues."
},
{
"category": "information",
"description": "Emails seeking general information, clarifications, or communication that doesn\u2019t fit Support, Sales, or Complaints."
}
]
}
},
"typeVersion": 1.1
},
{
"id": "bcf2a2b4-2f78-47f3-bd1d-500f3eff0851",
"name": "Set 2",
"type": "n8n-nodes-base.set",
"position": [
-400,
528
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "b47eaf61-7201-45b5-993a-cbcfaa5765f7",
"name": "Decision",
"type": "string",
"value": "Compliants"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f26299b0-795b-46c7-b255-0588a9976f50",
"name": "Set 3",
"type": "n8n-nodes-base.set",
"position": [
-400,
784
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "b47eaf61-7201-45b5-993a-cbcfaa5765f7",
"name": "Decision",
"type": "string",
"value": "Info"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "7f458771-5e7f-4fcb-be7d-da4349bda1e6",
"name": "Set 4",
"type": "n8n-nodes-base.set",
"position": [
-400,
1040
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "b47eaf61-7201-45b5-993a-cbcfaa5765f7",
"name": "Decision",
"type": "string",
"value": "Other"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "cf5a3309-f478-418a-9ff3-d8dfb7cc3c8c",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
-464,
480
],
"parameters": {
"color": 4,
"height": 192,
"content": "## Set the decision"
},
"typeVersion": 1
},
{
"id": "6262ee85-fef2-4c99-ac5a-c57b0e5e4fff",
"name": "Sticky Note8",
"type": "n8n-nodes-base.stickyNote",
"position": [
-464,
736
],
"parameters": {
"color": 4,
"height": 192,
"content": "## Set the decision"
},
"typeVersion": 1
},
{
"id": "e2abc12a-b6ad-4f15-abc7-13735439ab90",
"name": "Sticky Note9",
"type": "n8n-nodes-base.stickyNote",
"position": [
-464,
992
],
"parameters": {
"color": 4,
"height": 192,
"content": "## Set the decision"
},
"typeVersion": 1
},
{
"id": "41e62dfb-3838-499c-984c-e0057030ab4f",
"name": "Google Sheets2",
"type": "n8n-nodes-base.googleSheets",
"position": [
192,
784
],
"parameters": {
"columns": {
"value": {
"Decision": "={{ $json.Decision }}",
"Original Email": "=Subject: {{ $('Gmail Trigger').item.json.headers.subject }}\nBody: {{ $('Gmail Trigger').item.json.text }}"
},
"schema": [
{
"id": "Original Email",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Original Email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Decision",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Decision",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Output Email",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "Output Email",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE/edit#gid=0",
"cachedResultName": "Hoja 1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE/edit?usp=drivesdk",
"cachedResultName": "Log Email Automation"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 4.6
},
{
"id": "cc204b45-f8bb-4f07-98f7-52e55f6e79c2",
"name": "Google Sheets",
"type": "n8n-nodes-base.googleSheets",
"position": [
480,
-48
],
"parameters": {
"columns": {
"value": {
"Decision": "={{ $json.Decision }}",
"Output Email": "=Subject: {{ $json.Subject_email }}\nBody: {{ $json.Body_email }}",
"Original Email": "=Subject: {{ $('Gmail Trigger').item.json.headers.subject }}\nBody: {{ $('Gmail Trigger').item.json.text }}"
},
"schema": [
{
"id": "Original Email",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Original Email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Decision",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Decision",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Output Email",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Output Email",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE/edit#gid=0",
"cachedResultName": "Hoja 1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE/edit?usp=drivesdk",
"cachedResultName": "Log Email Automation"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 4.6
},
{
"id": "a4f688e0-5cdb-4454-a344-159add0f83af",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"position": [
-48,
784
],
"parameters": {},
"typeVersion": 1
},
{
"id": "3210d7da-9a37-47d2-b66f-28f16b9998b2",
"name": "No Operation, do nothing1",
"type": "n8n-nodes-base.noOp",
"position": [
288,
-48
],
"parameters": {},
"typeVersion": 1
},
{
"id": "0a55cbc0-ef79-496f-af1d-d420761a17cb",
"name": "Sticky Note10",
"type": "n8n-nodes-base.stickyNote",
"position": [
-704,
48
],
"parameters": {
"color": 5,
"width": 884,
"height": 392,
"content": "## Automatic Response Sales"
},
"typeVersion": 1
},
{
"id": "67177cb9-e14b-438b-91b0-af64395dde65",
"name": "Sticky Note11",
"type": "n8n-nodes-base.stickyNote",
"position": [
-704,
-352
],
"parameters": {
"color": 5,
"width": 884,
"height": 376,
"content": "## Automatic Response Support"
},
"typeVersion": 1
},
{
"id": "635385df-9465-42ee-8e86-8996d1fe33d2",
"name": "Sticky Note12",
"type": "n8n-nodes-base.stickyNote",
"position": [
-128,
64
],
"parameters": {
"color": 4,
"height": 240,
"content": "## Set the decision"
},
"typeVersion": 1
},
{
"id": "bb0f23e1-caa2-4a3c-843d-c753d05af101",
"name": "Sticky Note13",
"type": "n8n-nodes-base.stickyNote",
"position": [
-128,
-336
],
"parameters": {
"color": 4,
"height": 240,
"content": "## Set the decision"
},
"typeVersion": 1
},
{
"id": "e81d3f4d-b225-478e-9f85-0ed9064dcad1",
"name": "Add label to thread",
"type": "n8n-nodes-base.gmail",
"position": [
-288,
288
],
"parameters": {
"labelIds": [
"Label_3720213495654917937"
],
"resource": "thread",
"threadId": "={{ $('Gmail Trigger').item.json.threadId }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "8b549ecf-6957-4789-9353-379f3fb35b38",
"name": "Create a draft: Sales",
"type": "n8n-nodes-base.gmail",
"position": [
-288,
128
],
"parameters": {
"message": "={{ $json.message.content.Body }}",
"options": {
"sendTo": "={{ $('Gmail Trigger').item.json.from.value[0].address }}",
"threadId": "={{ $('Gmail Trigger').item.json.threadId }}"
},
"subject": "={{ $json.message.content.Subject }}",
"resource": "draft"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "1aec5594-f0a0-41e0-af09-63fbfafc4f1e",
"name": "Add label to thread1",
"type": "n8n-nodes-base.gmail",
"position": [
-288,
-128
],
"parameters": {
"labelIds": [
"Label_7294717935753585870"
],
"resource": "thread",
"threadId": "={{ $('Gmail Trigger').item.json.threadId }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "ebfc12bd-f8bb-4590-b25f-09ab4e9a1fd5",
"name": "Create a draft: Support",
"type": "n8n-nodes-base.gmail",
"position": [
-288,
-288
],
"parameters": {
"message": "={{ $json.message.content.Body }}",
"options": {
"sendTo": "={{ $('Gmail Trigger').item.json.from.value[0].address }}",
"threadId": "={{ $('Gmail Trigger').item.json.threadId }}"
},
"subject": "={{ $json.message.content.Subject }}",
"resource": "draft"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "bb8c3533-c0a8-47d1-bf4d-834daaa778d3",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1184,
736
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "91a3f31d-aa81-4df0-967b-b594bcf49513",
"name": "Message a model: Support",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
-608,
-208
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "id",
"value": "gpt-4.1-mini"
},
"options": {},
"messages": {
"values": [
{
"content": "=Hemos recibido el siguiente mensaje de {{ $('Gmail Trigger').item.json.headers.from.replace(/^From:\\s*/, '').match(/^(.*?)(?=\\s*<)/)[1] }}:\n\n\"{{ $('Gmail Trigger').item.json.text }}\"\n\nRedacta una respuesta profesional en funci\u00f3n del mensaje y esta informaci\u00f3n.\n"
},
{
"role": "assistant",
"content": "=You are an AI assistant for a professional company. \nGenerate a polite and concise email reply to a support request. \nThe output must always be in valid JSON with two fields: Subject and Body.\n\nRules:\n- Subject: short and professional, e.g. \"We received your request\".\n- Body: acknowledge receipt, mention that support will contact them shortly, under 80 words.\n- Keep tone professional and friendly.\n- Personalize with the sender's name if available.\n- Do not add anything outside the JSON.\n\nExamples of proper JSON outputs:\n{\n \"Subject\": \"We received your request\",\n \"Body\": \"Hi John, thank you for reaching out. Our support team will review your issue and contact you shortly.\"\n}\n{\n \"Subject\": \"Support request received\",\n \"Body\": \"Hello Sarah, we\u2019ve received your message. A specialist will contact you soon to assist you.\"\n}\n"
}
]
},
"jsonOutput": true
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"executeOnce": false,
"retryOnFail": true,
"typeVersion": 1.8
},
{
"id": "bf409083-7bd8-42ff-a88a-7d0f7f73da69",
"name": "Message a model: Sales",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
-624,
208
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "id",
"value": "gpt-4.1-mini"
},
"options": {},
"messages": {
"values": [
{
"content": "=Hemos recibido el siguiente mensaje de {{ $('Gmail Trigger').item.json.headers.from.replace(/^From:\\s*/, '').match(/^(.*?)(?=\\s*<)/)[1] }}:\n\n\"{{ $('Gmail Trigger').item.json.text }}\"\n\nRedacta una respuesta profesional en funci\u00f3n del mensaje y esta informaci\u00f3n.\n"
},
{
"role": "assistant",
"content": "=You are an AI assistant for a professional company. \nGenerate a polite and concise email reply to a sales inquiry. \nThe output must always be in valid JSON with two fields: Subject and Body.\n\nRules:\n- Subject: short and professional, e.g. \"Thank you for your interest\".\n- Body: thank them for their interest, mention the sales team will get back shortly, under 80 words.\n- Keep tone professional and friendly.\n- Personalize with the sender's name if available.\n- Do not add anything outside the JSON.\n\nExamples of proper JSON outputs:\n{\n \"Subject\": \"Thank you for your interest\",\n \"Body\": \"Hi Anna, thank you for your interest in our services. Our sales team will contact you shortly to discuss your needs.\"\n}\n{\n \"Subject\": \"We appreciate your inquiry\",\n \"Body\": \"Hello Peter, we appreciate your message. A member of our sales team will reach out soon with more details.\"\n}\n\n"
}
]
},
"jsonOutput": true
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"retryOnFail": true,
"typeVersion": 1.8
},
{
"id": "639b1fb2-53c4-4231-9347-bc481fc0fc31",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-704,
1232
],
"parameters": {
"color": 3,
"width": 512,
"height": 224,
"content": "## You can add as much as you need"
},
"typeVersion": 1
},
{
"id": "84f2f08a-7ff3-4ed1-916e-939ca497a944",
"name": "Append row in sheet",
"type": "n8n-nodes-base.googleSheets",
"position": [
-1168,
1072
],
"parameters": {
"columns": {
"value": {
"Time": "={{ $now.format('dd-MM-yyyy hh:mm:ss') }}",
"Workflow ID": "={{ $workflow.id }}",
"Execution ID": "={{ $execution.id }}",
"Error Message": "={{ $json.execution.error.message }}",
"Node with Error": "={{ $json.execution.lastNodeExecuted }}"
},
"schema": [
{
"id": "Node with Error",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Node with Error",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Error Message",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Error Message",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Time",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Time",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Execution ID",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Execution ID",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Workflow ID",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Workflow ID",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"Error"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 390118099,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE/edit#gid=390118099",
"cachedResultName": "Errors"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SutRXvFjLnnbnakCTNN0O4LqsG-y5nPGDXmipk3EAzE/edit?usp=drivesdk",
"cachedResultName": "Log Email Automation"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 4.7
},
{
"id": "6b9fa983-ec6c-4a7c-bda7-e922ad9ae19c",
"name": "Error Trigger",
"type": "n8n-nodes-base.errorTrigger",
"position": [
-1344,
1072
],
"parameters": {},
"typeVersion": 1
},
{
"id": "114acc6a-897b-4c73-a596-76f089e93cd0",
"name": "Set",
"type": "n8n-nodes-base.set",
"position": [
-64,
-288
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "b47eaf61-7201-45b5-993a-cbcfaa5765f7",
"name": "Decision",
"type": "string",
"value": "Sales"
},
{
"id": "35d39d93-dbfa-43ec-8100-6df72a2874db",
"name": "Subject_email",
"type": "string",
"value": "={{ $('Message a model: Support').item.json.message.content.Subject }}"
},
{
"id": "ed3606d1-16ca-4089-8398-df6490e9e8ad",
"name": "Body_email",
"type": "string",
"value": "={{ $('Message a model: Support').item.json.message.content.Body }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "32f8f930-2db3-4d3f-9134-11d40cd2f655",
"name": "Set 1",
"type": "n8n-nodes-base.set",
"position": [
-64,
128
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "b47eaf61-7201-45b5-993a-cbcfaa5765f7",
"name": "Decision",
"type": "string",
"value": "Sales"
},
{
"id": "35d39d93-dbfa-43ec-8100-6df72a2874db",
"name": "Subject_email",
"type": "string",
"value": "={{ $('Message a model: Sales').item.json.message.content.Subject }}"
},
{
"id": "ed3606d1-16ca-4089-8398-df6490e9e8ad",
"name": "Body_email",
"type": "string",
"value": "={{ $('Message a model: Sales').item.json.message.content.Body }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "28a2c29e-c959-4a2e-ae80-5afec769d8cd",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2176,
48
],
"parameters": {
"color": 3,
"width": 688,
"height": 1328,
"content": "# Email Automation Workflow\n\n## Overview\n### Automates email classification in Gmail and generates drafts using OpenAI and Google Sheets. Emails are categorized as Support, Sales, Complaints, Information, or Other, labeled accordingly, draft responses are created, and logs and errors are recorded.\n\n---\n\n## Quick Start\n\n1. **Gmail Trigger** \n - Detects new emails every minute.\n\n2. **Email Classification** \n - Categories: `support`, `sales`, `complaints`, `information`, `other`...\n\n3. **Actions by Category** \n - **Support / Sales:** generates Gmail draft with Subject and Body. \n - **Complaints / Information / Other:** applies label to the email.\n\n4. **Google Sheets Logging** \n - **Logs:** `Original Email`, `Decision`, `Output Email`. \n - **Errors:** `Node with Error`, `Error Message`, `Time`, `Execution ID`, `Workflow ID`. \n - Make sure nodes reference the correct `documentId` and `sheetName`.\n\n5. **Error Handling** \n - `Error Trigger` automatically records workflow errors in the Errors sheet.\n\n---\n\n## Quick Start Checklist\n\n- [ ] Configure Gmail OAuth2 credentials. \n- [ ] Set up OpenAI credentials for Support and Sales nodes. \n- [ ] Create Google Sheets with `Logs` and `Errors` sheets and the correct columns. \n- [ ] Verify `documentId` and `sheetName` in all Sheets nodes. \n- [ ] Check classification and labeling nodes. \n- [ ] Test with a sample email to confirm draft creation and logging.\n---\n\nReady to activate: add credentials, check sheet IDs, and test with a sample email.\n"
},
"typeVersion": 1
}
],
"connections": {
"Set": {
"main": [
[
{
"node": "No Operation, do nothing1",
"type": "main",
"index": 0
}
]
]
},
"Set 1": {
"main": [
[
{
"node": "No Operation, do nothing1",
"type": "main",
"index": 0
}
]
]
},
"Set 2": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Set 3": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Set 4": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"info label": {
"main": [
[
{
"node": "Set 3",
"type": "main",
"index": 0
}
]
]
},
"other label": {
"main": [
[
{
"node": "Set 4",
"type": "main",
"index": 0
}
]
]
},
"Error Trigger": {
"main": [
[
{
"node": "Append row in sheet",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Mail Classifier",
"type": "main",
"index": 0
}
]
]
},
"Mail Classifier": {
"main": [
[
{
"node": "Message a model: Support",
"type": "main",
"index": 0
}
],
[
{
"node": "Message a model: Sales",
"type": "main",
"index": 0
}
],
[
{
"node": "compliants label",
"type": "main",
"index": 0
}
],
[
{
"node": "info label",
"type": "main",
"index": 0
}
],
[
{
"node": "other label",
"type": "main",
"index": 0
}
],
[],
[],
[]
]
},
"compliants label": {
"main": [
[
{
"node": "Set 2",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Mail Classifier",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Add label to thread": {
"main": [
[]
]
},
"Create a draft: Sales": {
"main": [
[
{
"node": "Set 1",
"type": "main",
"index": 0
}
]
]
},
"Message a model: Sales": {
"main": [
[
{
"node": "Create a draft: Sales",
"type": "main",
"index": 0
},
{
"node": "Add label to thread",
"type": "main",
"index": 0
}
]
]
},
"Create a draft: Support": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Message a model: Support": {
"main": [
[
{
"node": "Add label to thread1",
"type": "main",
"index": 0
},
{
"node": "Create a draft: Support",
"type": "main",
"index": 0
}
]
]
},
"No Operation, do nothing": {
"main": [
[
{
"node": "Google Sheets2",
"type": "main",
"index": 0
}
]
]
},
"No Operation, do nothing1": {
"main": [
[
{
"node": "Google Sheets",
"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.
gmailOAuth2googleSheetsOAuth2ApiopenAiApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This n8n template demonstrates how to automate email classification, labeling, draft generation, and logging using Gmail, OpenAI, and Google Sheets. Use cases include customer support management, sales inquiry handling, and keeping track of incoming emails efficiently in a…
Source: https://n8n.io/workflows/7839/ — 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.
Detects new unread Gmail messages Extracts sender name for personalized replies Classifies the email into one of four categories Applies the correct Gmail label and either sends an auto-reply, creates
This section automates Gmail message handling through AI-powered classification and response. Using the LangChain Text Classifier, incoming emails are analyzed and sorted into four categories — High P
This n8n template uses AI to automatically classify incoming Gmail messages into five categories and route them to the right people or departments. It can also reply automatically and send WhatsApp al
Email Automation AI-Powered Operations Internal Productivity Tools
This workflow automatically classifies incoming Gmail messages into categories such as High Priority, Inquiry, and Finance/Billing, and then generates professional draft replies using GPT-4. By combin