AutomationFlowsAI & RAG › Read, Analyze, and Auto-reply to Gmail Emails with Openai, Slack, and Sheets

Read, Analyze, and Auto-reply to Gmail Emails with Openai, Slack, and Sheets

ByOneclick AI Squad @oneclick-ai on n8n.io

A fully automated, AI-powered email assistant built in n8n that reads incoming emails, understands their intent and sentiment, classifies them by category, drafts intelligent context-aware replies, and sends them automatically — all without any human intervention. Built using…

Event trigger★★★★☆ complexityAI-powered20 nodesGmail TriggerSlackGmailGoogle SheetsOpenAI
AI & RAG Trigger: Event Nodes: 20 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #13830 — we link there as the canonical source.

This workflow follows the Gmail → Gmail Trigger 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 →

Download .json
{
  "id": "oyibPEl0MDo1b9I8",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "n8n OpenCWL AI Email Automation: Read, Analyze & Auto-Reply to Emails",
  "tags": [],
  "nodes": [
    {
      "id": "3c182993-eac4-45d7-948a-f48c58feec2d",
      "name": "Overview & Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2032,
        -64
      ],
      "parameters": {
        "width": 1200,
        "height": 1080,
        "content": "## \ud83d\udce7 n8n OpenCWL AI Email Automation\n### Read, Analyze & Auto-Reply to Emails Intelligently\n\n---\n\n### \ud83d\udccb Description\nA fully automated, AI-powered email assistant built in n8n that reads incoming emails, understands their intent and sentiment, classifies them by category, drafts intelligent context-aware replies, and sends them automatically \u2014 all without any human intervention. Built using OpenAI + Gmail/SMTP integration for any business or team.\n\n---\n\n### \ud83c\udfaf What's the Goal?\nReplace slow, manual email handling with an always-on AI email assistant that reads every incoming message, understands what the sender needs, and responds instantly with a professional, personalized reply \u2014 escalating only when truly necessary.\n\n---\n\n### \ud83d\udca1 Why Does It Matter?\nEmail overload is one of the biggest productivity killers for businesses. Teams spend hours every day reading, triaging, and replying to repetitive messages \u2014 support requests, meeting inquiries, sales questions, and more. This workflow automates the entire cycle: inbox \u2192 understand \u2192 reply \u2192 log \u2192 escalate, saving hours per day while improving response times from hours to seconds.\n\n---\n\n### \u2699\ufe0f How It Works\n1. Gmail trigger polls inbox for new unread emails\n2. Email content (subject + body) is extracted and cleaned\n3. AI classifies email: Support / Sales / Meeting / Complaint / Spam / General\n4. Sentiment is analyzed: Positive / Neutral / Negative / Urgent\n5. AI drafts a professional, context-aware reply based on classification\n6. If sentiment is Urgent or Negative \u2192 escalate to human via Slack\n7. If routine \u2192 auto-send reply via Gmail\n8. Email thread logged to Google Sheets (sender, category, sentiment, reply)\n9. Slack notification sent with summary for team awareness\n10. Label applied in Gmail for organization & tracking\n\n---\n\n### \ud83d\udd27 Configuration Requirements\n- **Gmail OAuth2** (for reading inbox and sending replies)\n- **OpenAI API key** (for classification, sentiment & reply generation)\n- **Google Sheets OAuth2** (for email log & analytics)\n- **Slack Bot Token** (for escalation alerts & team summaries)\n- **Optional: SMTP credentials** (if using non-Gmail provider)\n- **Optional: CRM webhook** (to sync contacts & interactions)\n\n---\n\n### \ud83d\ude80 Setup Guide\n1. Import this workflow into your n8n instance\n2. Connect credentials: Gmail OAuth2, OpenAI, Google Sheets, Slack\n3. Open the **Set Email Config** node and configure:\n   - `check_interval_minutes` \u2014 how often to poll inbox (recommended: 5)\n   - `auto_reply_categories` \u2014 which categories to auto-reply (e.g. Support, General)\n   - `escalate_categories` \u2014 which to escalate (e.g. Complaint, Urgent)\n   - `sender_name` \u2014 your name or business name for reply signature\n   - `log_sheet_id` \u2014 Google Sheets document ID for logging\n   - `slack_channel` \u2014 channel name for escalation alerts\n4. Customize reply templates in the **Set Reply Templates** node\n5. Run a test with a sample email using the manual trigger\n6. Verify reply quality in Gmail Sent folder\n7. Check Google Sheets log for the entry\n8. Activate workflow \u2014 it will now monitor inbox automatically\n9. Monitor escalation volume in Slack and tune thresholds weekly\n\n---\n\n### \ud83d\udcde Contact Us\nNeed help setting up or customizing this workflow for your business?\n\ud83d\udc49 https://www.oneclickitsolution.com/contact-us/\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "48a97cfe-4b2c-4c6a-a7e0-b811739bf9bc",
      "name": "1. Trigger",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3264,
        -48
      ],
      "parameters": {
        "color": 3,
        "width": 480,
        "height": 760,
        "content": "## 1. Trigger & Fetch Email\nGmail polling \u2192 extract & clean email content"
      },
      "typeVersion": 1
    },
    {
      "id": "2476c991-8e66-4b38-9ea3-d485b278723a",
      "name": "2. Analysis Phase",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3760,
        -48
      ],
      "parameters": {
        "color": 5,
        "width": 520,
        "height": 740,
        "content": "## 2. AI Analysis\nClassify category + analyze sentiment with OpenAI"
      },
      "typeVersion": 1
    },
    {
      "id": "319e1676-ac9a-49f6-8544-886cf5d14231",
      "name": "3. Reply Generation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4304,
        -48
      ],
      "parameters": {
        "color": 4,
        "width": 520,
        "height": 720,
        "content": "## 3. Draft AI Reply\nGenerate professional context-aware email reply"
      },
      "typeVersion": 1
    },
    {
      "id": "79e277f5-9303-4e32-a49d-de860225e7e1",
      "name": "4. Escalation Gate",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4832,
        -48
      ],
      "parameters": {
        "color": 6,
        "width": 420,
        "height": 700,
        "content": "## 4. Escalation Gate\nUrgent / Negative \u2192 human escalation via Slack"
      },
      "typeVersion": 1
    },
    {
      "id": "5b6b0a70-da91-4938-9d9c-7496ca132387",
      "name": "5. Output Phase",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5280,
        -48
      ],
      "parameters": {
        "color": 3,
        "width": 560,
        "height": 696,
        "content": "## 5. Send, Log & Notify\nAuto-reply \u2192 Gmail label \u2192 Sheets log \u2192 Slack summary"
      },
      "typeVersion": 1
    },
    {
      "id": "478335d7-4034-4d79-9024-3bcf6c923ddb",
      "name": "Gmail: Watch Inbox",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        3360,
        336
      ],
      "parameters": {
        "filters": {
          "readStatus": "unread"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyX",
              "unit": "minutes",
              "value": 5
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1033c995-f15f-4dab-955d-6131d369edf6",
      "name": "Schedule (fallback)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        3360,
        544
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "a7d974c1-2cd1-4911-adcf-2875fd4de29a",
      "name": "Set Email Config",
      "type": "n8n-nodes-base.set",
      "position": [
        3584,
        448
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "sender_name",
              "value": "OneClick IT Solution Support Team"
            },
            {
              "name": "company_name",
              "value": "OneClick IT Solution"
            },
            {
              "name": "contact_url",
              "value": "https://www.oneclickitsolution.com/contact-us/"
            },
            {
              "name": "auto_reply_categories",
              "value": "Support,General,Sales,Meeting"
            },
            {
              "name": "escalate_sentiments",
              "value": "Urgent,Negative"
            },
            {
              "name": "slack_channel",
              "value": "email-escalations"
            },
            {
              "name": "log_sheet_id",
              "value": "your-google-sheet-id-here"
            },
            {
              "name": "gmail_label",
              "value": "AI-Processed"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "a0548987-a4ab-4221-b071-0603d27a388c",
      "name": "Extract & Clean Email",
      "type": "n8n-nodes-base.code",
      "position": [
        3584,
        240
      ],
      "parameters": {
        "jsCode": "const email = $input.item.json;\nconst subject = email.subject || '(No Subject)';\nconst body = (email.text || email.snippet || '').substring(0, 2000).replace(/<[^>]*>/g, '').trim();\nconst sender = email.from || email.sender || 'user@example.com';\nconst messageId = email.id || email.messageId || '';\nconst threadId = email.threadId || '';\nreturn {\n  subject,\n  body,\n  sender,\n  messageId,\n  threadId,\n  preview: body.substring(0, 200)\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "29ce75be-be3f-421d-9e29-2cafb0e7098e",
      "name": "Parse Analysis",
      "type": "n8n-nodes-base.code",
      "position": [
        4080,
        336
      ],
      "parameters": {
        "jsCode": "const raw = $input.item.json.message.content.replace(/```json|```/g, '').trim();\nconst analysis = JSON.parse(raw);\nconst emailData = $('Extract & Clean Email').item.json;\nreturn {\n  ...analysis,\n  subject: emailData.subject,\n  body: emailData.body,\n  sender: emailData.sender,\n  messageId: emailData.messageId,\n  threadId: emailData.threadId\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "417dd630-1057-4bdb-bad1-afd2e13af06b",
      "name": "Prepare Reply Data",
      "type": "n8n-nodes-base.code",
      "position": [
        4560,
        336
      ],
      "parameters": {
        "jsCode": "const replyBody = $input.item.json.message.content;\nconst analysis = $('Parse Analysis').item.json;\nreturn {\n  reply_body: replyBody,\n  reply_subject: 'Re: ' + analysis.subject,\n  sender: analysis.sender,\n  category: analysis.category,\n  sentiment: analysis.sentiment,\n  priority: analysis.priority,\n  requires_human: analysis.requires_human,\n  intent: analysis.intent,\n  messageId: analysis.messageId,\n  threadId: analysis.threadId,\n  needs_escalation: analysis.sentiment === 'Urgent' || analysis.sentiment === 'Negative' || analysis.requires_human === true || analysis.priority === 'Critical'\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "82e780f4-26c4-44ad-8033-56aeaeea56ae",
      "name": "Needs Escalation?",
      "type": "n8n-nodes-base.if",
      "position": [
        4896,
        336
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.needs_escalation }}",
              "value2": true
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0dc708d1-55fe-4815-9a10-e255515d2826",
      "name": "Slack: Escalate to Human",
      "type": "n8n-nodes-base.slack",
      "position": [
        5120,
        240
      ],
      "parameters": {
        "text": "={{ '\ud83d\udea8 *Email Escalation Required*\\n\\n*From:* ' + $json.sender + '\\n*Subject:* ' + $json.reply_subject.replace('Re: ', '') + '\\n*Category:* ' + $json.category + '  |  *Sentiment:* ' + $json.sentiment + '  |  *Priority:* ' + $json.priority + '\\n*Intent:* ' + $json.intent + '\\n\\n*AI Draft Reply (review before sending):*\\n' + $json.reply_body.substring(0, 500) + '...\\n\\n\u26a0\ufe0f This email requires a human response. Please reply directly in Gmail.' }}",
        "channel": "={{ $('Set Email Config').item.json.slack_channel }}",
        "attachments": [],
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b6035a37-a4ca-4995-9054-824a5d60b011",
      "name": "Gmail: Send Auto-Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        5120,
        448
      ],
      "parameters": {
        "sendTo": "={{ $json.sender }}",
        "message": "={{ $json.reply_body }}",
        "options": {},
        "subject": "={{ $json.reply_subject }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "c8669435-35e5-40a6-9393-88ad4b08f64c",
      "name": "Gmail: Apply Label",
      "type": "n8n-nodes-base.gmail",
      "position": [
        5312,
        448
      ],
      "parameters": {
        "operation": "addLabel"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "e37d7b66-fa7a-4da0-9cc7-966acd423785",
      "name": "Google Sheets: Log Email",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        5520,
        448
      ],
      "parameters": {
        "columns": {
          "value": {
            "Intent": "={{ $('Prepare Reply Data').item.json.intent }}",
            "Sender": "={{ $('Prepare Reply Data').item.json.sender }}",
            "Subject": "={{ $('Prepare Reply Data').item.json.reply_subject.replace('Re: ', '') }}",
            "Category": "={{ $('Prepare Reply Data').item.json.category }}",
            "Priority": "={{ $('Prepare Reply Data').item.json.priority }}",
            "Escalated": "={{ $('Prepare Reply Data').item.json.needs_escalation ? 'Yes' : 'No' }}",
            "Sentiment": "={{ $('Prepare Reply Data').item.json.sentiment }}",
            "Timestamp": "={{ $now.toISO() }}",
            "Reply Preview": "={{ $('Prepare Reply Data').item.json.reply_body.substring(0, 300) }}",
            "Auto-Reply Sent": "={{ $('Prepare Reply Data').item.json.needs_escalation ? 'No' : 'Yes' }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "mode": "string",
          "value": "Email Log"
        },
        "documentId": {
          "mode": "string",
          "value": "={{ $('Set Email Config').item.json.log_sheet_id }}"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "ce85af1e-b5b9-480c-a75d-b8de6a2d9e20",
      "name": "Slack: Notify Team",
      "type": "n8n-nodes-base.slack",
      "position": [
        5712,
        448
      ],
      "parameters": {
        "text": "={{ '\u2705 *AI Email Auto-Reply Sent*\\n\\n*To:* ' + $('Prepare Reply Data').item.json.sender + '\\n*Subject:* ' + $('Prepare Reply Data').item.json.reply_subject.replace('Re: ','') + '\\n*Category:* ' + $('Prepare Reply Data').item.json.category + '  |  *Sentiment:* ' + $('Prepare Reply Data').item.json.sentiment + '\\n*Priority:* ' + $('Prepare Reply Data').item.json.priority + '\\n\u2709\ufe0f Reply sent & logged to Sheets automatically.' }}",
        "channel": "={{ $('Set Email Config').item.json.slack_channel }}",
        "attachments": [],
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e3b68a44-4931-4684-81e4-ed432d7fbb71",
      "name": "OpenAI: Classify & Analyze",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        3824,
        336
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {}
          ]
        },
        "resource": "conversation"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f445b94e-32c6-4a11-b221-b8bfaa931414",
      "name": "OpenAI: Draft Reply",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        4368,
        336
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {}
          ]
        },
        "resource": "conversation"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2b902e04-1c20-4b49-985b-c3a1597b6494",
  "connections": {
    "Parse Analysis": {
      "main": [
        [
          {
            "node": "OpenAI: Draft Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Email Config": {
      "main": [
        [
          {
            "node": "OpenAI: Classify & Analyze",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs Escalation?": {
      "main": [
        [
          {
            "node": "Slack: Escalate to Human",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gmail: Send Auto-Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail: Apply Label": {
      "main": [
        [
          {
            "node": "Google Sheets: Log Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail: Watch Inbox": {
      "main": [
        [
          {
            "node": "Extract & Clean Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Reply Data": {
      "main": [
        [
          {
            "node": "Needs Escalation?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack: Notify Team": {
      "main": [
        []
      ]
    },
    "OpenAI: Draft Reply": {
      "main": [
        [
          {
            "node": "Prepare Reply Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule (fallback)": {
      "main": [
        [
          {
            "node": "Set Email Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract & Clean Email": {
      "main": [
        [
          {
            "node": "Set Email Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail: Send Auto-Reply": {
      "main": [
        [
          {
            "node": "Gmail: Apply Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets: Log Email": {
      "main": [
        [
          {
            "node": "Slack: Notify Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI: Classify & Analyze": {
      "main": [
        [
          {
            "node": "Parse Analysis",
            "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.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

A fully automated, AI-powered email assistant built in n8n that reads incoming emails, understands their intent and sentiment, classifies them by category, drafts intelligent context-aware replies, and sends them automatically — all without any human intervention. Built using…

Source: https://n8n.io/workflows/13830/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Complete AI-powered sales system Automates lead capture, qualification, and follow-up from multiple channels. AI INTELLIGENCE:

Gmail Trigger, Google Sheets, OpenAI +3
AI & RAG

Overview

Gmail Trigger, Google Drive, OpenAI +4
AI & RAG

Small teams, solo operators, and security-conscious individuals who receive email attachments from external senders. Useful for freelancers, agencies, HR teams, and anyone handling CVs, invoices, or d

Gmail Trigger, HTTP Request, OpenAI +4
AI & RAG

This workflow is a comprehensive, AI-powered system that acts as a virtual support manager. It automates the entire process of handling incoming support tickets, ensuring speed, accuracy, and efficien

Gmail Trigger, OpenAI, Slack +3
AI & RAG

An automated quote generation system that monitors your inbox, classifies quote requests using AI, calculates intelligent pricing based on historical data, and provides a professional dashboard for re

Gmail Trigger, OpenAI, Supabase +2