AutomationFlowsAI & RAG › Gmail Email Categorization & Auto Reply with Gpt-4o and Google Sheets

Gmail Email Categorization & Auto Reply with Gpt-4o and Google Sheets

ByHaruki Kuwai @harukikuwai8098 on n8n.io

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 Priority, Advertisement, Inquiry, and Finance/Billing — each triggering a…

Event trigger★★★★☆ complexityAI-powered18 nodesGmail TriggerText ClassifierOpenAI ChatGmailOpenAIGoogle Sheets
AI & RAG Trigger: Event Nodes: 18 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #10118 — 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": "6MZqIrk7nB6lc4vB",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Gmail Auto Reply & Categorization with AI",
  "tags": [],
  "nodes": [
    {
      "id": "9f88a550-a517-4362-a71f-b7997b9c75fa",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -272,
        0
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "faf382e9-f898-447f-b5a1-d7a8c28d2309",
      "name": "Text Classifier",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        -96,
        -32
      ],
      "parameters": {
        "options": {},
        "inputText": "={{ $json.text }}",
        "categories": {
          "categories": [
            {
              "category": "High Priority",
              "description": "Description: Emails that require immediate attention and could have a serious impact if delayed. Typical examples include: system outages, security alerts, critical legal notices, or urgent requests from executives or key clients. Examples: '[URGENT] Service outage notice', '[IMPORTANT] Contract renewal deadline'"
            },
            {
              "category": "Advertisement",
              "description": "Description: Marketing or promotional emails that do not require an immediate response. Typical examples include: sales announcements, product launches, newsletters, and event invitations. Examples: '[LIMITED OFFER] 50% off campaign', 'New service release announcement'"
            },
            {
              "category": "Inquiry",
              "description": "Description: Customer or partner inquiries that require a reply or follow-up. Typical examples include: product or service questions, quote requests, reservations, troubleshooting, repair or refund requests. Examples: 'Inquiry about studio reservation', 'Request for quotation'"
            },
            {
              "category": "Finance/Billing",
              "description": "Description: Emails related to payments, invoices, or financial transactions. Typical examples include: invoices, receipts, payment confirmations, bank or accounting notifications, and tax-related documents. Examples: 'Invoice submission notice', '[Payment confirmed] Thank you for your payment'"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "aaddb0e0-fd5f-49ab-8887-f3ecc5bd9d89",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -96,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {
          "maxRetries": 1
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "52265538-92f0-45b9-a7e8-78ba934620cf",
      "name": "Save Priority Mail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        -240
      ],
      "parameters": {
        "labelIds": [
          "Label_6395372519299544115"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "a3ac1d27-05ca-4832-bee9-176899915b27",
      "name": "Save Advertisement Mail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        -48
      ],
      "parameters": {
        "labelIds": [
          "Label_2877175876700118240"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "696b4433-3093-436c-b98d-2f910858823e",
      "name": "Save Inquiry Mail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        144
      ],
      "parameters": {
        "labelIds": [
          "Label_8971387974199578288"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "68f89db1-59b8-4b15-8ac6-52354a28093a",
      "name": "Save Finance Mail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        336
      ],
      "parameters": {
        "labelIds": [
          "Label_7818902445747119871"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "cdb0c68f-e041-47ef-b65e-14e2c476a760",
      "name": "Generate Priority Draft",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        -240
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are an executive assistant.  \nYour task is to reply accurately to high-priority incoming emails.  \nHere is the email you need to respond to: {{ $('Gmail Trigger').item.json.text }}  \n\nPlease output the following parameters:\n- Subject  \n- Message\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "a59b0fc2-b11e-4e9c-a5c6-b5aa33f85bac",
      "name": "Generate Ad Summary",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        -48
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a marketing specialist.  \nYour task is to summarize incoming promotional or marketing emails concisely in 1\u20132 lines for spreadsheet logging.  \n\nHere is the received email: {{ $('Gmail Trigger').item.json.text }}\n\nPlease extract and summarize the following fields:\n- Sender  \n- Subject  \n- Summary  \n- Recommendation\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "64f4df61-ee88-4ea0-857f-7d738c2f3c21",
      "name": "Generate Finance Summary",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        144
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a customer service representative.  \nYour task is to reply accurately to customer inquiries.  \nIf the question cannot be answered, instruct the sender to contact the following number: 000-0000-000.  \n\nHere is the email you need to respond to: {{ $('Gmail Trigger').item.json.text }}\n\nPlease output the following parameters:\n- Subject  \n- Message\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "a8df46ff-73f7-4129-94cb-0f452b328716",
      "name": "Generate Inquiry Reply",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        336
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a finance and billing assistant.  \nYour task is to summarize emails related to invoices, payments, and financial notifications in a concise manner.  \n\nHere is the received email: {{ $('Gmail Trigger').item.json.text }}\n\nPlease output the following parameters:\n- Subject  \n- Message\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "ef15e762-463f-4acd-9c38-cb84735c9feb",
      "name": "Create Draft",
      "type": "n8n-nodes-base.gmail",
      "position": [
        992,
        -240
      ],
      "parameters": {
        "message": "={{ $json.message.content['message'] }}",
        "options": {},
        "subject": "={{ $json.message.content['send'] }}",
        "resource": "draft"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "45aa5109-f0c2-43e7-a91a-db0fcc109cc7",
      "name": "Append Row to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        992,
        -48
      ],
      "parameters": {
        "columns": {
          "value": {
            "Sender": "={{ $json.message.content['Sender'] }}",
            "Subject": "={{ $json.message.content['Subject'] }}",
            "Summary": "={{ $json.message.content['Summary'] }}",
            "Recommendation": "={{ $json.message.content['Recommendation'] }}"
          },
          "schema": [
            {
              "id": "Sender",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Recommendation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Recommendation",
              "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/13AmknC94wJ5n1FDl7E1yUFsCNYVDJklzPpTZmFQrMb4/edit#gid=0",
          "cachedResultName": "01_Advertisement Mail Summary"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "13AmknC94wJ5n1FDl7E1yUFsCNYVDJklzPpTZmFQrMb4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13AmknC94wJ5n1FDl7E1yUFsCNYVDJklzPpTZmFQrMb4/edit?usp=drivesdk",
          "cachedResultName": "[n8n] Advertisement Mail Summary"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "6701a84f-2e2a-42f2-9c98-fb7ee3f394f1",
      "name": "Send Finance Mail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        992,
        144
      ],
      "parameters": {
        "message": "={{ $json.message.content['message'] }}",
        "options": {},
        "resource": "thread",
        "threadId": "={{ $('Save Inquiry Mail').item.json.threadId }}",
        "messageId": "={{ $('Save Inquiry Mail').item.json.id }}",
        "operation": "reply"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "89129a16-1f1a-48e4-82f1-0593c142909b",
      "name": "Reply to Inquiry",
      "type": "n8n-nodes-base.gmail",
      "position": [
        992,
        336
      ],
      "parameters": {
        "sendTo": "{{YOUR_EMAIL_ADDRESS}}",
        "message": "={{ $json.message.content['message'] }}",
        "options": {},
        "subject": "={{ $json.message.content['send'] }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "6f1a41f5-ad3e-4b4b-906d-44a20bbe0623",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        -304
      ],
      "parameters": {
        "width": 416,
        "height": 880,
        "content": "## \ud83d\udce9Gmail Auto Reply & Categorization with AI (LangChain + OpenAI + Google Sheets)\n\n**Description:**\nThis workflow automatically categorizes incoming Gmail messages into four types \u2014 High Priority, Advertisement, Inquiry, and Finance/Billing \u2014 using the LangChain Text Classifier.\nEach category triggers a specific automated action powered by OpenAI GPT models:\n\n\ud83d\udfe5 High Priority: Generates an AI-written draft reply in Gmail.\n\n\ud83d\udfe8 Advertisement: Summarizes the content and logs it to Google Sheets.\n\n\ud83d\udfe9 Inquiry: Creates an auto-reply email with fallback instructions.\n\n\ud83d\udfe6 Finance/Billing: Generates a brief summary and forwards it to a designated address.\n\nThis setup combines Gmail + LangChain + OpenAI + Google Sheets for a complete AI-driven email management system that reduces manual sorting and response time.\n\n**Setup Instructions:**\n\nConnect your credentials for Gmail, Google Sheets, and OpenAI.\n\nReplace all placeholders such as {{YOUR_EMAIL_ADDRESS}}, {{YOUR_SPREADSHEET_ID}}, and label names with your actual values.\n\nMake sure you have Gmail labels created for \u201cAdvertisement,\u201d \u201cInquiry,\u201d etc.\n\n(Optional) Translate prompts back to your language if needed.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "49d044e4-0a1c-4fff-b205-77d43db01251",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -176
      ],
      "parameters": {
        "color": 2,
        "width": 512,
        "height": 496,
        "content": "## \u2460Receive Gmail \u2192 AI understands the email content\nIncoming emails are analyzed by AI and automatically categorized into four sections: High Priority, Advertisement, Inquiry, and Finance/Billing."
      },
      "typeVersion": 1
    },
    {
      "id": "904ff69b-74bc-4c26-aa3d-5af797548e7e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -624
      ],
      "parameters": {
        "width": 960,
        "height": 1200,
        "content": "## \u2461Email Processing Section\n**Flow Overview:**\nThis workflow automatically classifies all incoming Gmail messages into four categories using the LangChain Text Classifier and performs specific actions for each:\n\n\ud83d\udfe5 High Priority: Gmail adds a \u201cHigh Priority\u201d label \u2192 OpenAI generates a reply draft \u2192 saved as a Gmail draft.\n\n\ud83d\udfe8 Advertisement: AI summarizes the email \u2192 summary is recorded into a Google Sheet for later review.\n\n\ud83d\udfe9 Inquiry: AI generates an automatic customer reply \u2192 sends a polite response or fallback message.\n\n\ud83d\udfe6 Finance/Billing: AI creates a short summary of financial or billing-related content \u2192 forwards it to a designated email address.\n\n**Purpose:**\nThe system ensures that each type of incoming email is handled automatically and intelligently: urgent messages are drafted quickly, promotional content is logged, customer inquiries are answered promptly, and financial communications are safely redirected \u2014 all through a single AI-powered workflow."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "fa5d38ad-f0cb-4b9a-962d-295da7453ed7",
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "Save Priority Mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Advertisement Mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Inquiry Mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Finance Mail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Save Finance Mail": {
      "main": [
        [
          {
            "node": "Generate Inquiry Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Inquiry Mail": {
      "main": [
        [
          {
            "node": "Generate Finance Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Priority Mail": {
      "main": [
        [
          {
            "node": "Generate Priority Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Ad Summary": {
      "main": [
        [
          {
            "node": "Append Row to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Inquiry Reply": {
      "main": [
        [
          {
            "node": "Reply to Inquiry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Priority Draft": {
      "main": [
        [
          {
            "node": "Create Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Advertisement Mail": {
      "main": [
        [
          {
            "node": "Generate Ad Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Finance Summary": {
      "main": [
        [
          {
            "node": "Send Finance Mail",
            "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

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 Priority, Advertisement, Inquiry, and Finance/Billing — each triggering a…

Source: https://n8n.io/workflows/10118/ — 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

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, sale

Gmail Trigger, Gmail, Text Classifier +4
AI & RAG

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

Gmail Trigger, OpenAI Chat, Gmail +4
AI & RAG

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

Gmail Trigger, OpenAI Chat, Gmail +3
AI & RAG

Email Automation AI-Powered Operations Internal Productivity Tools

Gmail Trigger, Text Classifier, OpenAI Chat +3
AI & RAG

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

Gmail Trigger, Gmail, Text Classifier +2