🔓 Unlock all 10,000+ workflows & prompts free Join Newsletter →
✅ Full access unlocked — explore all 10,000 AI workflow and prompt templates Browse Templates →
Home n8n Workflow
January 22, 2026

Gmail + OpenAI: qualify leads and reply in-thread

Lisa Granqvist Partner Workflow Automation Expert

Your inbox is full, but only a slice of it actually matters. The rest is newsletters, “quick questions” that go nowhere, vendor pitches, and vague enquiries that steal attention from real buyers.

This lead reply automation hits sales teams hardest, but founders and marketing managers feel it too. You end up responding late, missing good leads, or wasting about 2 hours a day on triage you shouldn’t be doing.

This workflow screens incoming email with OpenAI, qualifies the real leads, and sends a polished reply in the same thread. You’ll see what it does, what you need, and how to avoid the common traps.

How This Automation Works

See how this solves the problem:

n8n Workflow Template: Gmail + OpenAI: qualify leads and reply in-thread

The Challenge: Inbox Triage That Hides Real Leads

Manual inbox triage sounds simple until you’re living inside it. You open a message, scan for intent, check who sent it, decide if it’s worth replying, then try to write something that sounds human (and on-brand) while you’re already behind. The mental load is the sneaky part. Every “maybe” email steals context from the work you were doing, and that context switching keeps happening all day. Worse, the best leads often look boring at first glance, so they sit too long and cool off.

It adds up fast. Here’s where it usually breaks down in real teams.

  • You read the same email twice because you were interrupted mid-reply.
  • Good leads wait in the inbox while you clear low-value messages “just to be safe.”
  • Replies get inconsistent, which means more back-and-forth and more time spent explaining basics.
  • Threading gets messy, so someone replies from the wrong email or starts a new thread by accident.

The Fix: Qualify Leads Automatically and Reply in the Same Thread

This workflow acts like a front-line inbox assistant that never gets tired. It watches your inbox in real time through IMAP, grabs each new message, and asks OpenAI a simple question: “Is this a lead?” If the answer is no, the workflow stops and nothing gets sent. If it is a lead, it generates a tailored reply based on your criteria and tone, then pulls the original Gmail message details so the response lands in the correct thread. The result feels like you responded quickly and thoughtfully, even if you were in meetings all morning.

The workflow starts the moment a new email arrives. OpenAI classifies it, then writes the response only for qualified messages. Finally, Gmail sends the reply as a threaded response, not a disconnected new email.

What Changes: Before vs. After

Real-World Impact

Say your inbox gets 40 new messages on a weekday. If you spend about 2 minutes opening and deciding what each one is, that’s roughly 80 minutes gone before you’ve even replied to anyone. Add another 5 minutes to write a decent response for just 6 real leads and you’re near 2 hours. With this workflow, you still review important threads, but the “is this worth a response?” part becomes automatic and lead replies can go out within a few minutes of arrival.

Requirements

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • IMAP-enabled email account for receiving new messages.
  • Gmail to fetch message IDs and reply in-thread.
  • OpenAI API key (get it from the OpenAI dashboard).

Skill level: Beginner. You’ll connect accounts, paste prompts, and run a few test emails.

Need help implementing this? Talk to an automation expert (free 15-minute consultation).

The Workflow Flow

A new email lands in your inbox. The IMAP listener watches a folder you choose (usually INBOX) and pulls in fresh messages as they arrive.

The email gets classified for lead intent. An OpenAI model reads the subject and body and returns a simple decision you can control with your prompt. If you want to treat “pricing,” “timeline,” or “demo request” as a lead, you can make that explicit.

Only qualified messages move forward. The filter prevents replies to noise, which is the whole point. No awkward auto-replies to newsletters, job seekers, or spam.

A tailored reply is written and sent in-thread. OpenAI drafts the response, then Gmail retrieves the original message metadata so n8n can send a proper threaded reply instead of starting a brand-new conversation.

You can easily modify the lead criteria and the reply tone to match your market and your brand voice. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Email Trigger with Incoming Mail Listener

This workflow starts by listening to your inbox for new emails via IMAP.

  1. Add the Incoming Mail Listener node to your canvas.
  2. Set Post Process Action to nothing.
  3. Credential Required: Connect your imap credentials.
If your IMAP server requires special settings (e.g., port or TLS), confirm those in your IMAP credential configuration before testing.

Step 2: Classify Leads with Lead Classification AI and Filter Them

The workflow uses an AI model to classify incoming emails as leads, then filters only qualified messages.

  1. Add the Lead Classification AI node and connect it after Incoming Mail Listener.
  2. Set Model to gpt-4o.
  3. In Messages, include the prompt content with the expression {{ $json.textPlain }} to pass the email body.
  4. Enable JSON Output by setting it to true.
  5. Credential Required: Connect your openAiApi credentials.
  6. Add the Filter Qualified Leads node after Lead Classification AI.
  7. Set the filter condition Left Value to {{ $json.message.content.lead.toBoolean() }} and keep the operator as is true.
⚠️ Common Pitfall: If the AI response isn’t valid JSON, Filter Qualified Leads will fail. Ensure the AI prompt strictly returns {"lead":"true/false"}.

Step 3: Generate Replies with Compose Tailored Reply

This step crafts a customized response for qualified leads using the incoming email content.

  1. Add the Compose Tailored Reply node after Filter Qualified Leads.
  2. Set Model to gpt-4o.
  3. In Messages, keep the training examples and set the final content to the expression {{ $('Incoming Mail Listener').item.json.textPlain }}.
  4. Credential Required: Connect your openAiApi credentials (this node has no credentials configured yet).
If you want brand-specific tone, adjust the system and example messages in Compose Tailored Reply.

Step 4: Retrieve and Reply via Gmail

The workflow finds the original email thread and sends a threaded response using Gmail.

  1. Add Retrieve Original Email after Compose Tailored Reply.
  2. Set Operation to getAll.
  3. Set Filters → q to =from:"{{ $('Incoming Mail Listener').item.json.from }}" subject:"{{ $('Incoming Mail Listener').item.json.subject }}".
  4. Credential Required: Connect your gmailOAuth2 credentials.
  5. Add Send Threaded Response after Retrieve Original Email.
  6. Set Operation to reply and Email Type to text.
  7. Set Message to {{ $('Compose Tailored Reply').item.json.message.content }}.
  8. Set Message ID to {{ $('Incoming Mail Listener').item.json.metadata['message-id'] }}.
  9. Credential Required: Connect your gmailOAuth2 credentials (this node has no credentials configured yet).
⚠️ Common Pitfall: If the Message ID is missing or incorrect, Gmail will send a new email instead of replying in-thread.

Step 5: Test & Activate Your Workflow

Verify each step and activate the workflow for production use.

  1. Click Execute Workflow and send a test email to the inbox monitored by Incoming Mail Listener.
  2. Confirm that Lead Classification AI outputs JSON with lead set to true or false.
  3. Verify the reply content generated by Compose Tailored Reply matches the tone you expect.
  4. Check Gmail: Send Threaded Response should reply in the same thread using the original message ID.
  5. When satisfied, toggle the workflow Active to enable automated replies.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Watch Out For

  • Gmail credentials can expire or need specific permissions. If things break, check the connected account inside n8n credentials and confirm Gmail API access first.
  • If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
  • Default prompts in AI nodes are generic. Add your brand voice early or you’ll be editing outputs forever.

Common Questions

How quickly can I implement this lead reply automation automation?

About 30 minutes if your IMAP, Gmail, and OpenAI accounts are ready.

Can non-technical teams implement this lead reply automation?

Yes. You won’t write code, but you will need to connect credentials and edit two AI prompts so they match your lead rules and tone.

Is n8n free to use for this lead reply automation workflow?

Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in OpenAI API costs, which are usually a few cents per day at low volume.

Where can I host n8n to run this automation?

Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.

How do I adapt this lead reply automation solution to my specific challenges?

Start by changing the prompt in the Lead Classification AI node so it matches your definition of a qualified lead (industry, budget signals, location, job title, and so on). Then adjust the Compose Tailored Reply node to include your offer, your usual next step, and any qualifiers you want to ask up front. Common tweaks include routing “maybe” leads to a human instead of auto-replying, adding a short calendar link line, and inserting a one-question qualifier to reduce dead-end calls.

Why is my Gmail connection failing in this workflow?

Usually it’s expired credentials or missing Gmail API permissions.

What’s the capacity of this lead reply automation solution?

On n8n Cloud Starter, you can usually handle a typical small-business inbox volume without issues. If you self-host, there’s no execution limit, so capacity mostly depends on your server and how many emails arrive at once. Practically, this workflow processes one email at a time and finishes in under a minute for most messages. If you expect bursts (like after a webinar), use a queue approach such as Split in Batches and monitor OpenAI rate limits.

Is this lead reply automation automation better than using Zapier or Make?

Often, yes, because n8n makes it easier to do “classify, filter, then reply in-thread” without paying extra for branching logic. Self-hosting also matters if you don’t want per-task pricing once volume grows. The biggest difference is control: you can shape the prompts, the filtering rules, and the Gmail threading logic in one place. Zapier or Make can still work if you want a very simple flow, but threaded email handling and AI gating can get fiddly. Talk to an automation expert if you want help picking the simplest option for your setup.

The workflow handles the repetitive inbox sorting and first replies, so you can spend your attention on real conversations. Set it up once, then let your inbox behave.

Need Help Setting This Up?

Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.

Lisa Granqvist

Workflow Automation Expert

Expert in workflow automation and no-code tools.

×

Use template

Get instant access to this n8n workflow Json file

💬
Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Launch login modal Launch register modal