Gmail + OpenAI: qualify leads and reply in-thread
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
flowchart LR
subgraph sg0["Filter leads Flow"]
direction LR
n0@{ icon: "mdi:message-outline", form: "rounded", label: "Email Trigger (IMAP)", pos: "b", h: 48 }
n1@{ icon: "mdi:swap-horizontal", form: "rounded", label: "Filter", pos: "b", h: 48 }
n2@{ icon: "mdi:message-outline", form: "rounded", label: "Get Message", pos: "b", h: 48 }
n3@{ icon: "mdi:message-outline", form: "rounded", label: "Reply to Message", pos: "b", h: 48 }
n4@{ icon: "mdi:robot", form: "rounded", label: "Filter leads", pos: "b", h: 48 }
n5@{ icon: "mdi:robot", form: "rounded", label: "Reply with customized message", pos: "b", h: 48 }
n1 --> n5
n2 --> n3
n4 --> n1
n0 --> n4
n5 --> n2
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n4,n5 ai
class n1 decision
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
| What This Eliminates | Impact You’ll See |
|---|---|
|
|
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.
- Add the Incoming Mail Listener node to your canvas.
- Set Post Process Action to
nothing. - Credential Required: Connect your imap credentials.
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.
- Add the Lead Classification AI node and connect it after Incoming Mail Listener.
- Set Model to
gpt-4o. - In Messages, include the prompt content with the expression
{{ $json.textPlain }}to pass the email body. - Enable JSON Output by setting it to
true. - Credential Required: Connect your openAiApi credentials.
- Add the Filter Qualified Leads node after Lead Classification AI.
- Set the filter condition Left Value to
{{ $json.message.content.lead.toBoolean() }}and keep the operator as is true.
{"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.
- Add the Compose Tailored Reply node after Filter Qualified Leads.
- Set Model to
gpt-4o. - In Messages, keep the training examples and set the final content to the expression
{{ $('Incoming Mail Listener').item.json.textPlain }}. - Credential Required: Connect your openAiApi credentials (this node has no credentials configured yet).
Step 4: Retrieve and Reply via Gmail
The workflow finds the original email thread and sends a threaded response using Gmail.
- Add Retrieve Original Email after Compose Tailored Reply.
- Set Operation to
getAll. - Set Filters → q to
=from:"{{ $('Incoming Mail Listener').item.json.from }}" subject:"{{ $('Incoming Mail Listener').item.json.subject }}". - Credential Required: Connect your gmailOAuth2 credentials.
- Add Send Threaded Response after Retrieve Original Email.
- Set Operation to
replyand Email Type totext. - Set Message to
{{ $('Compose Tailored Reply').item.json.message.content }}. - Set Message ID to
{{ $('Incoming Mail Listener').item.json.metadata['message-id'] }}. - Credential Required: Connect your gmailOAuth2 credentials (this node has no credentials configured yet).
Step 5: Test & Activate Your Workflow
Verify each step and activate the workflow for production use.
- Click Execute Workflow and send a test email to the inbox monitored by Incoming Mail Listener.
- Confirm that Lead Classification AI outputs JSON with
leadset totrueorfalse. - Verify the reply content generated by Compose Tailored Reply matches the tone you expect.
- Check Gmail: Send Threaded Response should reply in the same thread using the original message ID.
- When satisfied, toggle the workflow Active to enable automated replies.
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
About 30 minutes if your IMAP, Gmail, and OpenAI accounts are ready.
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.
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.
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.
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.
Usually it’s expired credentials or missing Gmail API permissions.
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.
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.