AutomationFlowsAI & RAG › Gmail with AI Worklow

Gmail with AI Worklow

Gmail with AI worklow. Uses gmailTrigger, gmail, agent, lmChatOpenRouter. Event-driven trigger; 8 nodes.

Event trigger★★★★☆ complexityAI-powered8 nodesGmail TriggerGmailAgentOpenRouter ChatOutput Parser StructuredGmail Tool
AI & RAG Trigger: Event Nodes: 8 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the Agent → Gmail recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "Gmail with AI worklow",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {}
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        -416,
        -48
      ],
      "id": "3a7435fb-8642-4186-a0e3-45a5d5ebf9ad",
      "name": "New Mail"
    },
    {
      "parameters": {
        "operation": "get",
        "messageId": "={{ $json.id }}"
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -176,
        -112
      ],
      "id": "4981bc31-e199-492e-be43-f72d9eb61324",
      "name": "Get a message",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You are a email responding agent.\n\nBelow are the content of latest email I got.\n\nSubject : {{ $json.Subject }}\n\nBody : {{ $json.snippet }}\n\nYou have to do 2 things.\n\n1. specify the label based on the email.\nUse the tool to get all the labels and there Id and mention both of them properly.\n\nlabel can be one of below : \n\ncourse,\ndoubts,\nsponsorship\n\n2. As a smart assistant please draft the response for me so that I can reply to my email. with subject and body\n\nMake sure that reply is very respectable and wherever required please explain student doubt in depth with example and alsp make sure that reply follow a strict HTML format so it is easy to read.\nYou do not have to add any css styling just give in simple html and add Your Instructor as best regard",
        "hasOutputParser": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        32,
        -160
      ],
      "id": "34b273dd-c20d-4973-abe7-e163164c3fe3",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": "deepseek/deepseek-chat-v3.1:free",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        -96,
        96
      ],
      "id": "b546d7bb-c88d-4b0b-9829-896677d58790",
      "name": "OpenRouter Chat Model"
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\"label\":\"doubt\",\n  \"label_id\":\"12423512\",\n    \"subject\":\"doubt_answer\",\n    \"body\":\"Hey Thanks for reaching out\"\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        304,
        64
      ],
      "id": "803e65b3-3476-4167-b3f2-9acbcadfa0bc",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "resource": "label",
        "returnAll": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Return_All', ``, 'boolean') }}"
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        160,
        48
      ],
      "id": "bc2aaa2b-a8dd-40c8-9366-1b4068ddaf61",
      "name": "Get many labels in Gmail",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('Get a message').item.json.id }}",
        "labelIds": "={{ $json.output.label_id }}"
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        384,
        -160
      ],
      "id": "194514f3-c350-4fdd-8549-337165b77932",
      "name": "Add label to message",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "={{ $('AI Agent').item.json.output.subject }}",
        "emailType": "html",
        "message": "={{ $('AI Agent').item.json.output.body }}",
        "options": {
          "threadId": "={{ $json.threadId }}",
          "sendTo": "={{ $('Get a message').item.json.From }}"
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        592,
        -160
      ],
      "id": "d402ba32-cfe0-4c22-b79d-1e2cdbd37cd7",
      "name": "Create a draft",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "New Mail": {
      "main": [
        [
          {
            "node": "Get a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a message": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Get many labels in Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Add label to message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add label to message": {
      "main": [
        [
          {
            "node": "Create a draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "0d4306b0-d84a-453a-a6bc-7564ad986b07",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "SX7VLbkjIlv9CH6e",
  "tags": [
    {
      "createdAt": "2025-10-03T16:35:45.143Z",
      "updatedAt": "2025-10-03T16:35:45.143Z",
      "id": "Ie1T8I5F5dfoBo9S",
      "name": "learning"
    },
    {
      "createdAt": "2025-10-05T04:27:36.751Z",
      "updatedAt": "2025-10-05T04:27:36.751Z",
      "id": "SNO8LfARlW1bOFyo",
      "name": "learnn8n"
    },
    {
      "createdAt": "2025-10-06T08:22:28.282Z",
      "updatedAt": "2025-10-06T08:22:28.282Z",
      "id": "xykOHjGYcJWPo9Mc",
      "name": "gmail"
    }
  ]
}

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

Gmail with AI worklow. Uses gmailTrigger, gmail, agent, lmChatOpenRouter. Event-driven trigger; 8 nodes.

Source: https://github.com/akagamikaizoku/n8n-gmail-automation-workflow/blob/main/Gmail_with_AI_worklow.json — 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 workflow automatically transforms your messy inbox into a neatly organized space while ensuring you never miss a critical message. It connects to your Gmail account and triggers for every new ema

Gmail Trigger, Output Parser Structured, Gmail Tool +8
AI & RAG

This n8n workflow automates sales processes using AI agents integrated with Airtable as a CRM and Gmail for email handling. It consists of two main workflows: one for handling Airtable status changes

Airtable Trigger, Agent, OpenAI Chat +9
AI & RAG

This n8n workflow automates email management by classifying incoming messages, drafting replies, and sending alerts—all powered by AI.

Sentiment Analysis, Lm Chat Azure Open Ai, Gmail +6
AI & RAG

N8N-Gmail-Ai-Auto-Labeler. Uses gmailTrigger, lmChatGoogleGemini, gmailTool, agent. Event-driven trigger; 25 nodes.

Gmail Trigger, Google Gemini Chat, Gmail Tool +3
AI & RAG

Automate admin tasks for manufacturing companies by processing emails, extracting key data from invoices & purchase orders, and delivering instant alerts via Gmail and Telegram.

Gmail Trigger, Gmail, Agent +4