AutomationFlowsEmail & Gmail › Ai-powered Lead Email Classification & Auto-reply with Gpt-4o and Gmail

Ai-powered Lead Email Classification & Auto-reply with Gpt-4o and Gmail

ByRodrigo @rodrigonzalezsyncra on n8n.io

This workflow automatically responds to incoming emails identified as potential leads using AI-generated text. It connects to your email inbox via IMAP, classifies incoming messages with an AI model, filters out non-leads, and sends a personalized reply to relevant messages.…

Manual trigger★★★★☆ complexityAI-powered12 nodesEmail Read ImapGmailOpenAI
Email & Gmail Trigger: Manual Nodes: 12 Complexity: ★★★★☆ AI nodes: yes Added:

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

This workflow follows the Gmail → OpenAI 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": "XOp3UmuOGm0uEUOP",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Email Autoreply Template",
  "tags": [],
  "nodes": [
    {
      "id": "46330a1e-99c2-4e0b-b2ef-fbc1ac382402",
      "name": "Email Trigger (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "notes": "Checks your email inbox for new incoming messages in real time using the IMAP protocol.\nThis node is the entry point of the workflow, capturing any new email so it can be processed.\nYou can configure it to watch a specific folder (e.g., INBOX, Leads).",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {},
        "postProcessAction": "nothing"
      },
      "credentials": {
        "imap": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "2a2a35ef-23cf-4612-ac7d-21f91f21a2c6",
      "name": "Filter",
      "type": "n8n-nodes-base.filter",
      "notes": "Filters out emails that are not classified as leads.\nOnly messages identified as leads will continue through the workflow for an automated reply.",
      "position": [
        608,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4da59f1a-dd10-450e-a113-d193b63fcdac",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.message.content.lead.toBoolean() }}",
              "rightValue": ""
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.2
    },
    {
      "id": "ddba86b4-fe7d-4c36-b42c-6dde939d05f4",
      "name": "Get Message",
      "type": "n8n-nodes-base.gmail",
      "notes": "Retrieves the full details of the original email, including the sender\u2019s address and the conversation thread, so the reply can be linked to the correct message.",
      "position": [
        1216,
        0
      ],
      "parameters": {
        "filters": {
          "q": "=from:\"{{ $('Email Trigger (IMAP)').item.json.from }}\" subject:\"{{ $('Email Trigger (IMAP)').item.json.subject }}\" "
        },
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f1b3f3c5-a2fe-436e-a272-d3958ccab3e5",
      "name": "Reply to Message",
      "type": "n8n-nodes-base.gmail",
      "notes": "Sends the AI-generated reply back to the sender as a direct response to their email.\nThe reply will appear as part of the same conversation thread in the recipient\u2019s inbox.",
      "position": [
        1536,
        0
      ],
      "parameters": {
        "message": "={{ $('Reply with customized message').item.json.message.content }}",
        "options": {},
        "emailType": "text",
        "messageId": "={{ $('Email Trigger (IMAP)').item.json.metadata['message-id'] }}",
        "operation": "reply"
      },
      "notesInFlow": true,
      "typeVersion": 2.1
    },
    {
      "id": "2489c348-5d8e-4564-915f-1d933eae745b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        -320
      ],
      "parameters": {
        "color": 3,
        "height": 256,
        "content": "## Reply to Message\nSends the AI-generated reply back to the sender as a direct response to their email.  \nThe reply will appear as part of the same conversation thread in the recipient\u2019s inbox.  \n[Guide](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.gmail/)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e7617aa6-1104-4cc9-af36-80d7c19cdc59",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -320
      ],
      "parameters": {
        "color": 4,
        "width": 208,
        "height": 256,
        "content": "## Email Trigger (IMAP)\nMake sure to replace you own [service/offer] in the prompt\nChecks your email inbox for new incoming messages in real time using the IMAP protocol.  \nThis node is the entry point of the workflow, capturing any new email so it can be processed.  \nYou can configure it to watch a specific folder (e.g., INBOX, Leads).  \n[Guide](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.emailimap/)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "33fe0c88-6540-4087-bb60-ac6c4de9f6d3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        -320
      ],
      "parameters": {
        "color": 7,
        "height": 256,
        "content": "## Is Lead? (Message Model)\nUses an AI model to analyze the incoming email and determine whether the sender is a potential lead.  \nThe AI looks for keywords, tone, and intent within the message to classify it as a lead or not.  \n"
      },
      "typeVersion": 1
    },
    {
      "id": "54c5cf98-a106-4e3b-ad2d-d57fb8095044",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -320
      ],
      "parameters": {
        "color": 5,
        "height": 256,
        "content": "## Filter\nFilters out emails that are NOT classified as leads.  \nOnly messages identified as leads will continue through the workflow for an automated reply.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "94aedcf9-6abb-40e0-9856-e2fc3a84116a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -320
      ],
      "parameters": {
        "color": 7,
        "height": 256,
        "content": "## Reply with customized message (Message Model)\nGenerates a personalized reply using AI based on the content of the incoming email.  \nMake sure to replace your own \"business/service\" in the prompt.\n\nThe response can be tailored to greet the sender, answer initial questions, and encourage further engagement.  "
      },
      "typeVersion": 1
    },
    {
      "id": "83e57764-c096-45fc-a475-0167caa7eeaf",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        -320
      ],
      "parameters": {
        "color": 3,
        "width": 256,
        "height": 256,
        "content": "## Get Message\nRetrieves the full details of the original email, including the sender\u2019s address and the conversation thread.  \nEnsures the reply is linked to the correct email conversation.  \n[Guide](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.gmail/)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4875fac3-0ca1-4d26-a116-3afcfe8477c9",
      "name": "Filter leads",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Uses an AI model to analyze the incoming email and determine whether the sender is a potential lead.\nThe AI looks for keywords, tone, and intent within the message to classify it as a lead or not.",
      "position": [
        240,
        0
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "= Indicate if the following message is a lead that's interested in my [service/offer]\n\nOutput as JSON {\"lead\": \"<true/false>\"}\n\n {{ $json.textPlain }}"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.8
    },
    {
      "id": "7c5f6533-c82e-4fa2-b794-c93b38903c7c",
      "name": "Reply with customized message",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Generates a personalized reply using AI based on the content of the incoming email.\nThe response can be tailored to greet the sender, answer initial questions, and encourage further engagement.",
      "position": [
        848,
        0
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "You're currently monitoring a sales email inbox for my [business and service you offer]. For every inquiry you receive, digest it and respond appropriately with a customized message that's tuned to the particular prospect. Make sure to use spartan, no-frills language."
            },
            {
              "content": "Name: Michael JacksonType: High-TicketMonthly Commitment: $8,000About: Hi I really want to get started on your high tickey monthly e-commerce offer - let me know how to start!"
            },
            {
              "role": "assistant",
              "content": "Hey Michael,\n\nNick here. Thanks for reaching out & I appreciate your interest in my high ticket e-commerce offer. Happy to help you get started!\n\nI just let someone on my team know about this & they'll give you a call in a couple of minutes to dive into detail. Looking forward\u00a0to working with you.\n\nCheers,\nSanti"
            },
            {
              "content": "={{ $('Email Trigger (IMAP)').item.json.textPlain }}"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.8
    }
  ],
  "active": false,
  "settings": {
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "versionId": "3d19076b-77ab-48ed-aa07-77e72067969c",
  "connections": {
    "Filter": {
      "main": [
        [
          {
            "node": "Reply with customized message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Message": {
      "main": [
        [
          {
            "node": "Reply to Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter leads": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "Filter leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply with customized message": {
      "main": [
        [
          {
            "node": "Get Message",
            "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 workflow automatically responds to incoming emails identified as potential leads using AI-generated text. It connects to your email inbox via IMAP, classifies incoming messages with an AI model, filters out non-leads, and sends a personalized reply to relevant messages.…

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

More Email & Gmail workflows → · Browse all categories →

Related workflows

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

Email & Gmail

Alrouf AI Integration (Production). Uses googleSheets, chainLlm, lmChatGoogleGemini, outputParserStructured. Manual trigger; 21 nodes.

Google Sheets, Chain Llm, Google Gemini Chat +5
Email & Gmail

This workflow automates your email communication by listening for incoming emails and notifying you via Telegram. It then prompts you to provide a quick response, which it transforms into a polished,

Email Read Imap, Email Send, OpenAI +1
Email & Gmail

Create E-Mail Responses With Fastmail And Openai. Uses httpRequest, splitOut, emailReadImap, openAi. Manual trigger; 11 nodes.

HTTP Request, Email Read Imap, OpenAI
Email & Gmail

This n8n workflow automates the drafting of email replies for Fastmail using OpenAI's GPT-4 model. Here’s the overall process: Email Monitoring: The workflow continuously monitors a specified IMAP inb

HTTP Request, Email Read Imap, OpenAI
Email & Gmail

In this guide, we’ll walk you through setting up an AI-driven workflow that automatically processes incoming emails using a custom AI model (e.g., Llama), prepares email content, and saves it as a Gma

Email Read Imap, Chain Llm, Lm Ollama +1