This workflow corresponds to n8n.io template #7855 — we link there as the canonical source.
This workflow follows the Chainllm → 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 →
{
"name": "AI Email Assistant - Smart Email Processing & Response",
"tags": [
"ai-assistant",
"email-automation",
"smart-inbox",
"productivity",
"business-automation"
],
"nodes": [
{
"id": "e94f2b5f-32a8-411a-ace4-cb3302ff16d2",
"name": "\ud83d\udccb Optional File Filtering",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
0
],
"parameters": {
"color": 3,
"width": 340,
"height": 320,
"content": "## \ud83c\udfaf File Type Filtering (Optional)\n\n**Switch between nodes:**\n- `GetBinaryDataALL` - Process all attachment types\n- `GetSpecificBinaryData` - Only PDF/XML files\n\n**Use case:** Filter sensitive file types for security\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "321bbe22-fa97-4b15-a511-0dec17ff3b3f",
"name": "\ud83d\udce7 Email Processing",
"type": "n8n-nodes-base.stickyNote",
"position": [
-3408,
3312
],
"parameters": {
"color": 7,
"width": 1009,
"height": 306,
"content": "## \ud83d\udce7 Email Processing Pipeline\n\n**Flow:**\n1. Receive new email\n2. Get conversation thread context\n3. Extract latest message content\n4. Process with AI for categorization\n\n**Features:**\n- Thread-aware responses\n- Context preservation\n- Batch processing\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "1300f978-4409-4ab5-92a9-1e2d1a9f8bf2",
"name": "\u270d\ufe0f Response Generation",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1184,
2800
],
"parameters": {
"color": 7,
"width": 583,
"height": 313,
"content": "## \u270d\ufe0f AI Response Generation\n\n**Capabilities:**\n- Context-aware responses\n- Professional tone matching\n- Multiple response options\n- Custom business voice\n\n**Output:** Draft email ready for review\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "80372ae4-e5f2-4b26-8dba-faba15d93540",
"name": "Auto-fixing Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserAutofixing",
"position": [
-1680,
3664
],
"parameters": {
"options": {}
},
"typeVersion": 1
},
{
"id": "eb06df2a-44dc-442e-9aea-e8ed3aafce27",
"name": "\ud83d\udd0d Email Analysis",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1840,
3312
],
"parameters": {
"color": 7,
"width": 383,
"height": 313,
"content": "## \ud83d\udd0d Email Classification\n\n**AI Analysis:**\n- Priority assessment (High/Medium/Low)\n- Category assignment\n- Urgency detection\n- Response requirements\n- Follow-up needs\n\n**Output:** Structured classification data\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "c336e363-4bde-43b3-8e6e-076e70b50757",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-1536,
3904
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"object\",\n \"required\": [\"metadata\", \"classification\", \"actions\"],\n \"properties\": {\n \"metadata\": {\n \"type\": \"object\",\n \"required\": [\"sender\", \"subject\", \"receivedDate\"],\n \"properties\": {\n \"sender\": {\n \"type\": \"string\",\n \"format\": \"email\"\n },\n \"subject\": {\n \"type\": \"string\",\n \"minLength\": 1\n },\n \"receivedDate\": {\n \"type\": \"string\",\n \"format\": \"date-time\"\n }\n }\n },\n \"classification\": {\n \"type\": \"object\",\n \"required\": [\n \"summary\",\n \"toReply\",\n \"urgent\",\n \"dateRelated\",\n \"attachmentsToUpload\",\n \"requiresFollowUp\",\n \"forwardToTeam\",\n \"priority\",\n \"label_ids\",\n \"label_categories\"\n ],\n \"properties\": {\n \"summaryOfEmail\": {\n \"type\": \"string\"\n },\n \"toReply\": {\n \"type\": \"boolean\"\n },\n \"urgent\": {\n \"type\": \"boolean\"\n },\n \"dateRelated\": {\n \"type\": \"boolean\"\n },\n \"attachmentsToUpload\": {\n \"type\": \"boolean\"\n },\n \"requiresFollowUp\": {\n \"type\": \"boolean\"\n },\n \"forwardToTeam\": {\n \"type\": \"boolean\"\n },\n \"priority\": {\n \"type\": \"string\",\n \"enum\": [\"High\", \"Medium\", \"Low\"]\n },\n \"label_ids\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n },\n \"minItems\": 1\n },\n \"label_categories\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n },\n \"minItems\": 1\n }\n }\n },\n \"actions\": {\n \"type\": \"object\",\n \"required\": [\n \"notes\",\n \"dueDate\",\n \"uploadAttachments\",\n \"createTask\",\n \"additionalTasks\"\n ],\n \"properties\": {\n \"notes\": {\n \"type\": \"string\"\n },\n \"dueDate\": {\n \"type\": \"string\",\n \"format\": \"date\"\n },\n \"uploadAttachments\": {\n \"type\": \"boolean\"\n },\n \"createTask\": {\n \"type\": \"boolean\"\n },\n \"additionalTasks\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\"\n }\n }\n }\n }\n },\n \"additionalProperties\": false\n}"
},
"typeVersion": 1.2
},
{
"id": "6f3996c0-bf26-4850-b324-b20253793f48",
"name": "\ud83c\udff7\ufe0f Smart Labeling",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1184,
3712
],
"parameters": {
"color": 7,
"width": 463,
"height": 373,
"content": "## \ud83c\udff7\ufe0f Smart Labeling System\n\n**Auto-assigns:**\n- Category-based labels\n- Priority indicators\n- Processing status ('digested')\n- Custom business labels\n\n**Benefits:**\n- Organized inbox\n- Easy filtering\n- Progress tracking\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "03c6a77e-abb9-4dc0-a05b-2bd664afd8a6",
"name": "\ud83d\udcce Attachment Handler",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1184,
3120
],
"parameters": {
"color": 7,
"width": 423,
"height": 273,
"content": "## \ud83d\udcce Attachment Processing\n\n**Features:**\n- Automatic upload to cloud storage\n- File type filtering (PDF, XML, etc.)\n- Duplicate detection\n- Organized file naming\n\n**Storage:** Google Drive integration\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "a98fb400-c660-4bd3-ac33-9483d26d2c10",
"name": "\ud83d\udea8 Alert System",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1184,
3424
],
"parameters": {
"color": 7,
"width": 243,
"height": 253,
"content": "## \ud83d\udea8 Urgent Notifications\n\n**Alert System:**\n- Instant notifications for urgent emails\n- Telegram/Slack integration\n- Email summary and quick actions\n- Direct Gmail links\n\n**Criteria:** AI-determined urgency\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "2cba2d61-7944-434c-96ef-2dc74ca5589c",
"name": "Check for Attachments",
"type": "n8n-nodes-base.if",
"position": [
-1168,
3248
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "22f8d83a-b7d1-4b4a-8967-4335c0d1f510",
"operator": {
"type": "object",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $('Email_Trigger').item.binary }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "24af5d4a-0543-478f-b484-0706e9e3d893",
"name": "Email_Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-3344,
3424
],
"parameters": {
"simple": false,
"filters": {
"q": "-from:me"
},
"options": {
"downloadAttachments": true
},
"pollTimes": {
"item": [
{
"mode": "everyHour"
}
]
}
},
"typeVersion": 1
},
{
"id": "d84fed31-2e78-43a3-beb1-94e1ad9cf433",
"name": "Get Conversation Thread",
"type": "n8n-nodes-base.gmail",
"position": [
-2880,
3424
],
"parameters": {
"options": {
"returnOnlyMessages": true
},
"resource": "thread",
"threadId": "={{ $('Email_Trigger').item.json.threadId }}",
"operation": "get"
},
"retryOnFail": true,
"typeVersion": 2.1
},
{
"id": "24ba4c20-2191-4333-86fe-ad07cc870125",
"name": "Get Latest Message ID",
"type": "n8n-nodes-base.limit",
"position": [
-2704,
3424
],
"parameters": {
"keep": "lastItems"
},
"typeVersion": 1
},
{
"id": "d0231c2f-3560-490d-8dfc-e29b251799a3",
"name": "Get Latest Message Content",
"type": "n8n-nodes-base.gmail",
"position": [
-2528,
3424
],
"parameters": {
"simple": false,
"options": {},
"messageId": "={{ $('Get Latest Message ID').item.json.id }}",
"operation": "get"
},
"executeOnce": false,
"retryOnFail": true,
"typeVersion": 2.1
},
{
"id": "60f5e786-607b-4007-ac5c-80c7d05d2be4",
"name": "AI Email Classifier",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
-1760,
3424
],
"parameters": {
"text": "=<message>\n{{ $('Get Latest Message Content').item.json.textAsHtml }} \n</message>\n\n<subject>\n{{ $('Get Latest Message Content').item.json.subject }}\n</subject>\n\n<metadata>\n{{ $('Get Latest Message Content').item.json.headers.from }}\n{{ $('Get Latest Message Content').item.json.headers.date }}\n</metadata>\n\n<attachments>\n{{ $('Email_Trigger').item.binary ? true : false }}\n</attachments>\n\n<categories>\n{{ JSON.stringify($('Get User Labels').all(), null, 2) }}\n</categories>\n\n<current_category_labels>\n{{ $('Email_Trigger').item.json.labelIds }}\n</current_category_labels>\n\n<message_thread>\n{{ $('Email_Trigger').item.json.textAsHtml }}\n</message_thread>",
"messages": {
"messageValues": [
{
"message": "=# Email Assessment Agent\n<role>\nYou are an intelligent email analysis system that evaluates incoming emails to determine their characteristics, priority, and required actions.\n</role>\n\n<scope>\nProcess and analyze email content and metadata to classify messages, determine response requirements, assess urgency, and identify attachment needs.\n</scope>\n\n<command>\nFor each email received, perform the following analysis steps:\n\nStep 1: Analyze the email content and metadata to extract key information\nStep 2: Classify the email using provided labels and categories\nStep 3: Determine response requirements and urgency\nStep 4: Check for attachment handling needs\nStep 5: Generate a comprehensive assessment in the specified JSON output format\n</command>\n\n<inputs>\n- message: The full email body text of the most recent message in the thread\n- subject: Email subject line\n- metadata: Sender information, received date, and any system flags\n- attachments: Boolean indicating presence of attachments\n- categories: List of label categories\n- categories_ids: List of associated label category IDs\n- message_thread: The full context from previous messages in the conversation\n</inputs>\n\n<constraints>\n- Must only use provided categories for classification\n- Classifications must be evidence-based from email content\n- Urgency assessment must align with defined criteria\n- Do not infer information not present in the email\n- Each email can have multiple labels\n- Response requirements must follow specified guidelines\n</constraints> \n\n<format>\nReturn a single JSON object with the following structure:\n```json\n{\n \"metadata\": {\n \"sender\": string,\n \"subject\": string,\n \"receivedDate\": string (ISO 8601)\n },\n \"classification\": {\n \"toReply\": boolean,\n \"urgent\": boolean,\n \"dateRelated\": boolean,\n \"attachmentsToUpload\": boolean,\n \"requiresFollowUp\": boolean,\n \"forwardToTeam\": boolean,\n \"priority\": \"High\" | \"Medium\" | \"Low\",\n \"label_ids\": string[],\n \"label_categories\": string[]\n },\n \"actions\": {\n \"notes\": string,\n \"dueDate\": string,\n \"uploadAttachments\": boolean,\n \"createTask\": boolean,\n \"additionalTasks\": string[]\n }\n}\n```\n\n<categorization_rules>\nAll categorization elements should be considered independent but related:\n\n**Response Required (toReply):**\n- Direct questions or requests\n- Time-sensitive matters requiring confirmation\n- Approval requests\n- RSVP requirements\n\n**Urgent Classification:**\n- Immediate business impact\n- System/security incidents\n- Time-critical deadlines\n- Crisis situations\n- Keywords: URGENT, EMERGENCY, CRITICAL, ASAP\n\n**Priority Levels:**\n- High: Urgent matters requiring immediate attention\n- Medium: Important but not time-critical\n- Low: Routine or informational messages\n\n**Follow-up Requirements:**\n- Multi-step processes\n- Future deadlines\n- Progress monitoring needs\n- Ongoing projects\n\n**Team Forwarding:**\n- Cross-departmental impact\n- Shared responsibilities\n- Knowledge sharing requirements\n- Collaborative projects\n</categorization_rules>"
}
]
},
"promptType": "define",
"hasOutputParser": true
},
"executeOnce": true,
"retryOnFail": true,
"typeVersion": 1.5
},
{
"id": "99c5bb8c-e0d0-4963-9b9c-6bbdc0be243b",
"name": "Smart Action Router",
"type": "n8n-nodes-base.switch",
"position": [
-1424,
3408
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "RESPONSE",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "6d9939fa-0ddd-4b1b-b607-e4a521384c71",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.output.classification.toReply }}",
"rightValue": ""
}
]
},
"renameOutput": true
},
{
"outputKey": "ATTACHMENTS",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "cb7c3b89-b19b-4e32-987b-7f462bc221cd",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.output.classification.attachmentsToUpload }}",
"rightValue": ""
}
]
},
"renameOutput": true
},
{
"outputKey": "ALERT",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "ca803c7f-8884-4e40-b818-03c46d545ada",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $json.output.classification.urgent }}",
"rightValue": ""
}
]
},
"renameOutput": true
},
{
"outputKey": "LABEL",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "bd20b778-b44f-4927-a337-f6cfae3ef590",
"operator": {
"type": "string",
"operation": "exists",
"singleValue": true
},
"leftValue": "=",
"rightValue": ""
}
]
},
"renameOutput": true
}
]
},
"options": {
"allMatchingOutputs": true
}
},
"retryOnFail": true,
"typeVersion": 3.2
},
{
"id": "48decbca-dbf9-4494-9190-f48248c0c461",
"name": "Aggregate Label IDs",
"type": "n8n-nodes-base.aggregate",
"position": [
-1120,
3872
],
"parameters": {
"options": {},
"fieldsToAggregate": {
"fieldToAggregate": [
{
"renameField": true,
"outputFieldName": "label_ids",
"fieldToAggregate": "output.classification.label_ids"
}
]
}
},
"typeVersion": 1
},
{
"id": "fbbba2ef-bea1-4814-abcd-f0f41288aeaa",
"name": "AI Response Generator",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
-1136,
2912
],
"parameters": {
"text": "=Subject: {{ $('Email_Trigger').item.json.subject }}\nMessage: {{ $('Email_Trigger').item.json.textAsHtml }}",
"messages": {
"messageValues": [
{
"message": "=# Professional Email Response Generator\n\n<guidelines>\n**Tone & Style:**\n- Use business casual tone, warm but professional\n- Be concise and direct\n- Mirror the formality level of the incoming email\n- Match the language and urgency of the incoming email\n\n**Structure:**\n- Start with \"Hi [Name]\"\n- For multi-point emails, use short paragraphs (2-3 sentences each)\n- End with \"Best Regards,\\n[YOUR NAME]\"\n\n**Response Types:**\nFor yes/no questions, provide two alternatives:\n[AFFIRMATIVE RESPONSE]\nOR - - - - - - -\n[NEGATIVE RESPONSE]\n\n**Content Guidelines:**\n- Never invent information\n- Use \"[PLACEHOLDER]\" for missing information \n- For SALES inquiries: Include next steps (call booking, demo scheduling)\n- For COMPLAINTS: Express understanding, provide clear resolution steps\n- Plain text only, no formatting\n- Keep sentences concise but informative\n\n**Key Response Principles:**\n- Address the specific issue/request\n- Provide clear next steps\n- Request any missing information\n- Set clear expectations\n- Maintain professional and warm tone\n- Include follow-up plan when needed\n\n**Customization Notes:**\n- Replace [YOUR NAME] with your actual name\n- Adjust tone to match your business style\n- Add company-specific information as needed\n</guidelines>"
}
]
},
"promptType": "define"
},
"typeVersion": 1.4
},
{
"id": "5bd3feb3-ccdb-4cc4-a3c8-ff161926bc78",
"name": "Upload to Google Drive",
"type": "n8n-nodes-base.googleDrive",
"position": [
-240,
3424
],
"parameters": {
"name": "={{ \n$('AI Email Classifier').item.json.output.metadata.receivedDate.toDateTime().format('yyyy.MM.dd')\n+ \" - \"\n+ $('Email_Trigger').item.json.from.value[0].address \n+ ' - ' \n+ $('Get All Attachments').item.json.fileName.split(\".\")[0] \n+ \".\" + $('Get All Attachments').item.json.fileName.split(\".\")[1]}}",
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive"
},
"options": {},
"folderId": {
"__rl": true,
"mode": "id",
"value": "YOUR_GOOGLE_DRIVE_FOLDER_ID"
}
},
"notesInFlow": true,
"retryOnFail": true,
"typeVersion": 3
},
{
"id": "3ce26cee-92d4-47fd-bb29-d7a7e25db396",
"name": "Create Draft Response",
"type": "n8n-nodes-base.gmail",
"position": [
-800,
2912
],
"parameters": {
"message": "={{ $('AI Response Generator').item.json.text.replace(/\\n/g, \"<br />\\n\") }}",
"options": {
"sendTo": "={{ $('Email_Trigger').item.json.headers.from }}",
"threadId": "={{ $('Email_Trigger').item.json.threadId }}"
},
"subject": "={{ $('Email_Trigger').item.json.headers.subject }}",
"resource": "draft",
"emailType": "html"
},
"retryOnFail": true,
"typeVersion": 2.1
},
{
"id": "d28fff76-9f61-4e8a-895c-719836c4d3e4",
"name": "Assign Classification Label",
"type": "n8n-nodes-base.gmail",
"position": [
-944,
3792
],
"parameters": {
"labelIds": "={{ $('Aggregate Label IDs').item.json.label_ids[0] }}",
"messageId": "={{ $('Email_Trigger').item.json.id }}",
"operation": "addLabels"
},
"notesInFlow": true,
"retryOnFail": true,
"typeVersion": 2.1
},
{
"id": "18d309f1-9b49-4d40-9fe3-fa553429520c",
"name": "Mark as Processed",
"type": "n8n-nodes-base.gmail",
"onError": "continueErrorOutput",
"position": [
-944,
3952
],
"parameters": {
"labelIds": [
"YOUR_PROCESSED_LABEL_ID"
],
"messageId": "={{ $('Email_Trigger').item.json.id }}",
"operation": "addLabels"
},
"notesInFlow": true,
"retryOnFail": true,
"typeVersion": 2.1
},
{
"id": "53c5c777-b382-4833-b306-8553c6750e83",
"name": "Send Urgent Alert",
"type": "n8n-nodes-base.telegram",
"position": [
-1136,
3504
],
"parameters": {
"text": "=\ud83d\udea8 URGENT EMAIL ALERT\n\n\ud83d\udc64 From: {{ $('Email_Trigger').item.json.from.value[0].name }}\n\ud83d\udce7 Subject: {{ $('Email_Trigger').item.json.subject }}\n\ud83d\udccb Summary: {{ $('AI Email Classifier').item.json.output.classification.summaryOfEmail }}\n\ud83d\udd17 Link: https://mail.google.com/mail/u/0/#inbox/{{ $('Email_Trigger').item.json.id }}",
"chatId": "YOUR_TELEGRAM_CHAT_ID",
"additionalFields": {
"appendAttribution": false
}
},
"typeVersion": 1.2
},
{
"id": "62efbada-38a3-4af7-9da2-7845bc77f7d2",
"name": "Check Existing Attachments",
"type": "n8n-nodes-base.googleDrive",
"onError": "continueErrorOutput",
"position": [
-720,
3248
],
"parameters": {
"filter": {
"folderId": {
"__rl": true,
"mode": "id",
"value": "YOUR_GOOGLE_DRIVE_FOLDER_ID"
}
},
"options": {},
"resource": "fileFolder",
"returnAll": true,
"queryString": "={{ \n$('AI Email Classifier').item.json.output.metadata.receivedDate.toDateTime().format('yyyy.MM.dd')\n+ \" - \"\n+ $('Email_Trigger').item.json.from.value[0].address \n+ ' - ' \n+ $('Get All Attachments').item.json.fileName.split(\".\")[0] \n+ \".\" + $('Get All Attachments').item.json.fileName.split(\".\")[1]}}"
},
"notesInFlow": true,
"retryOnFail": true,
"typeVersion": 3,
"alwaysOutputData": true
},
{
"id": "5cb3e686-2d64-499c-ab44-b944b003ed28",
"name": "Check if File Exists",
"type": "n8n-nodes-base.if",
"position": [
-560,
3248
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "44944380-9ba0-4cf7-abbb-aba711fb0b9a",
"operator": {
"type": "object",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $('Check Existing Attachments').item.json }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "caa13ad4-5365-4317-b41a-5616ee1d0229",
"name": "Merge Attachment Data",
"type": "n8n-nodes-base.merge",
"position": [
-400,
3424
],
"parameters": {
"mode": "chooseBranch",
"useDataOfInput": 2
},
"typeVersion": 3
},
{
"id": "1e5c5994-beb9-49e4-bdec-294b402bfb6b",
"name": "\u2601\ufe0f File Management",
"type": "n8n-nodes-base.stickyNote",
"position": [
-736,
3152
],
"parameters": {
"color": 7,
"width": 663,
"height": 453,
"content": "## \u2601\ufe0f Smart File Management\n\n**Features:**\n- Duplicate detection\n- Organized naming convention\n- Date-based filing\n- Sender identification\n\n**Format:** YYYY.MM.DD - sender@email.com - filename.ext\n\n**Integration:** Google Drive for secure storage\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "66d06be7-f7bd-454d-a58a-1259fd3b9adc",
"name": "\ud83e\udd16 Key Features",
"type": "n8n-nodes-base.stickyNote",
"position": [
-3408,
3104
],
"parameters": {
"color": 6,
"width": 360,
"height": 180,
"content": "## \ud83e\udd16 AI Email Assistant Features\n\n**Capabilities:**\n- Context-aware email responses\n- Automatic categorization & labeling \n- Draft generation in your voice\n- Urgent email notifications\n- Attachment management\n- Smart inbox organization\n\n**Time Saving:** 90% reduction in email processing time\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "df00bd54-36e1-4246-b29c-d4250365f423",
"name": "Process One by One",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-3120,
3424
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "b9fdba24-4f13-4e1c-be82-794952ac47ff",
"name": "Get All Gmail Labels",
"type": "n8n-nodes-base.gmail",
"position": [
-2368,
3424
],
"parameters": {
"resource": "label",
"returnAll": true
},
"typeVersion": 2.1
},
{
"id": "53facca0-81ec-4abe-9659-1faed1b6b901",
"name": "Filter User Labels",
"type": "n8n-nodes-base.if",
"position": [
-2224,
3424
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "2ae0a220-4198-41ed-9ee5-78ae7b774ef6",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Get All Gmail Labels').item.json.type }}",
"rightValue": "user"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "d4dd372d-6f65-4ed9-86a1-a0c6cd68f216",
"name": "Get User Labels",
"type": "n8n-nodes-base.aggregate",
"position": [
-2000,
3424
],
"parameters": {
"options": {
"mergeLists": true
},
"fieldsToAggregate": {
"fieldToAggregate": [
{
"fieldToAggregate": "id"
},
{
"fieldToAggregate": "name"
}
]
}
},
"typeVersion": 1
},
{
"id": "ebd400dc-2c39-4758-8112-1cf61dd1f97f",
"name": "AI Language Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1904,
3760
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"typeVersion": 1.2
},
{
"id": "53e9d481-ab4e-48f1-a893-f10c040e48f2",
"name": "\ud83d\udd04 Label Sync",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2384,
3312
],
"parameters": {
"color": 7,
"width": 509,
"height": 306,
"content": "## \ud83d\udd04 Dynamic Label Management\n\n**Features:**\n- Auto-syncs with Gmail labels\n- Uses only user-created labels\n- Updates classification categories\n- Maintains label consistency\n\n**Benefits:**\n- Always up-to-date categories\n- No manual label management\n- Flexible classification system\n\n**Double click** to edit. [Guide](https://docs.n8n.io/workflows/sticky-notes/)"
},
"typeVersion": 1
},
{
"id": "e17c366f-c3ad-4ed7-a1ca-c860e629cb9c",
"name": "Get Specific File Types",
"type": "n8n-nodes-base.function",
"position": [
-944,
2560
],
"parameters": {
"functionCode": "let results = [];\nconst emailData = $('Email_Trigger').item;\n\nif (emailData.binary) {\n for (const key of Object.keys(emailData.binary)) {\n const attachment = emailData.binary[key];\n const mimeType = attachment.mimeType;\n \n // Filter for specific file types (PDF, XML, JPG)\n if (mimeType === 'application/pdf' || \n mimeType === 'text/xml' || \n mimeType === 'application/xml' ||\n mimeType === 'image/jpeg') {\n results.push({\n json: {\n fileName: attachment.fileName,\n mimeType: attachment.mimeType\n },\n binary: {\n data: attachment\n }\n });\n }\n }\n}\n\nreturn results;"
},
"typeVersion": 1
},
{
"id": "07615955-7e0c-4c0c-af70-76633de51eb6",
"name": "Get All Attachments",
"type": "n8n-nodes-base.function",
"position": [
-896,
3248
],
"parameters": {
"functionCode": "let results = [];\nconst emailData = $('Email_Trigger').item;\n\nif (emailData.binary) {\n for (const key of Object.keys(emailData.binary)) {\n const attachment = emailData.binary[key];\n results.push({\n json: {\n fileName: attachment.fileName,\n mimeType: attachment.mimeType\n },\n binary: {\n data: attachment\n }\n });\n }\n}\n\nreturn results;"
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"connections": {
"Email_Trigger": {
"main": [
[
{
"node": "Process One by One",
"type": "main",
"index": 0
}
]
]
},
"Get User Labels": {
"main": [
[
{
"node": "AI Email Classifier",
"type": "main",
"index": 0
}
]
]
},
"AI Language Model": {
"ai_languageModel": [
[
{
"node": "AI Email Classifier",
"type": "ai_languageModel",
"index": 0
},
{
"node": "Auto-fixing Output Parser",
"type": "ai_languageModel",
"index": 0
},
{
"node": "AI Response Generator",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Mark as Processed": {
"main": [
[
{
"node": "Process One by One",
"type": "main",
"index": 0
}
]
]
},
"Filter User Labels": {
"main": [
[
{
"node": "Get User Labels",
"type": "main",
"index": 0
}
]
]
},
"Process One by One": {
"main": [
[],
[
{
"node": "Get Conversation Thread",
"type": "main",
"index": 0
}
]
]
},
"AI Email Classifier": {
"main": [
[
{
"node": "Smart Action Router",
"type": "main",
"index": 0
}
]
]
},
"Aggregate Label IDs": {
"main": [
[
{
"node": "Mark as Processed",
"type": "main",
"index": 0
},
{
"node": "Assign Classification Label",
"type": "main",
"index": 0
}
]
]
},
"Get All Attachments": {
"main": [
[
{
"node": "Check Existing Attachments",
"type": "main",
"index": 0
},
{
"node": "Merge Attachment Data",
"type": "main",
"index": 1
}
]
]
},
"Smart Action Router": {
"main": [
[
{
"node": "AI Response Generator",
"type": "main",
"index": 0
}
],
[
{
"node": "Check for Attachments",
"type": "main",
"index": 0
}
],
[
{
"node": "Send Urgent Alert",
"type": "main",
"index": 0
}
],
[
{
"node": "Aggregate Label IDs",
"type": "main",
"index": 0
}
]
]
},
"Check if File Exists": {
"main": [
[],
[
{
"node": "Merge Attachment Data",
"type": "main",
"index": 0
}
]
]
},
"Get All Gmail Labels": {
"main": [
[
{
"node": "Filter User Labels",
"type": "main",
"index": 0
}
]
]
},
"AI Response Generator": {
"main": [
[
{
"node": "Create Draft Response",
"type": "main",
"index": 0
}
]
]
},
"Check for Attachments": {
"main": [
[
{
"node": "Get All Attachments",
"type": "main",
"index": 0
}
]
]
},
"Get Latest Message ID": {
"main": [
[
{
"node": "Get Latest Message Content",
"type": "main",
"index": 0
}
]
]
},
"Merge Attachment Data": {
"main": [
[
{
"node": "Upload to Google Drive",
"type": "main",
"index": 0
}
]
]
},
"Get Conversation Thread": {
"main": [
[
{
"node": "Get Latest Message ID",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Auto-fixing Output Parser",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Auto-fixing Output Parser": {
"ai_outputParser": [
[
{
"node": "AI Email Classifier",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Check Existing Attachments": {
"main": [
[
{
"node": "Check if File Exists",
"type": "main",
"index": 0
}
]
]
},
"Get Latest Message Content": {
"main": [
[
{
"node": "Get All Gmail Labels",
"type": "main",
"index": 0
}
]
]
}
}
}
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
A sophisticated n8n workflow that transforms your email management with AI-powered classification, automatic responses, and intelligent organization.
Source: https://n8n.io/workflows/7855/ — 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.
This workflow gives you the ability to reply to a long email with a voice note, rather than having to type everything out.
This workflow automates document processing using LlamaParse to extract and analyze text from various file formats. It intelligently processes documents, extracts structured data, and delivers actiona
This workflow contains community nodes that are only compatible with the self-hosted version of n8n.
🤖🧑💻 AI Agent for Top n8n Creators Leaderboard Reporting. Uses httpRequest, lmChatOpenAi, executeWorkflowTrigger, toolWorkflow. Event-driven trigger; 49 nodes.
🤖🧑💻 AI Agent for Top n8n Creators Leaderboard Reporting. Uses httpRequest, lmChatOpenAi, executeWorkflowTrigger, toolWorkflow. Event-driven trigger; 49 nodes.