How I built an n8n AI agent that reads and replies to email on its own
To reply to inbound email on its own, you run one n8n flow. It reads new replies over IMAP, cleans up the message, and asks an AI model to read the tone and write a short answer. A Switch node sends opt-outs to a suppression list and everyone else to a threaded Gmail reply. Every action gets logged, so nothing is a black box.
I built this after a cold-outreach campaign buried me in replies. I was reading each one and typing the same handful of answers over and over. So I built this flow, and I still run it. Here is the whole thing: why it matters, the usual ways people handle replies, how mine works, and how to point it at your own inbox.
The problem
A campaign that works gives you a reply pile. Answering it well takes time you do not have.
Send a few hundred cold emails and the replies come back all day. Some people are keen. Some are confused. Some just want off your list, and if you miss them you land in a spam trap. Each reply needs a read, a judgment call, and a short answer in the right tone. Do it by hand and you lose an hour a day, you answer late, and a tired person types the wrong thing. Skip it and warm leads go cold while opt-outs pile up.
The load is heavy. The average professional now gets over 120 emails a day (Radicati), and older McKinsey work put email at about 28 percent of the workweek. Most of it is routine, and it still lands on a person.
How most teams deal with it today
There are three common ways to handle a reply pile. Each has a catch.
Answer every reply by hand
Free, and the tone is yours. But it eats an hour a day, the answers come late, and the boring ones (stop, not interested, quick question) still get typed out one at a time. It falls apart the week a campaign actually lands.
Canned autoresponders and rules
Gmail templates and filters fire fast and cost nothing. But they cannot read tone. They send the same line to a keen lead and to someone asking to be removed, which is exactly how you annoy people and hit spam complaints.
A paid helpdesk or AI inbox tool
Tools like Front or Intercom can triage and suggest replies. They work, but they bill every seat every month, the rules live in their box and not yours, and bending them to a cold-outreach flow is often more work than it saves.
The fix
You own it, it costs almost nothing to run, and it bends to your voice and your rules.
One n8n flow does the boring part for you. It watches the mailbox, reads each real reply, works out what the person wants, and writes a short answer back in the same thread. Opt-outs get a clean removal and go on the suppression list. Here is what it does, in three parts.
It reads the reply
Every inbound reply is scored for intent and tone. The model decides if the person is interested, confused, annoyed, or asking to be left alone, and returns a confidence percent plus a one-line reason for its call.
It drafts a human answer
The reply is short, plainspoken, and threaded back to the sender so it looks like a real conversation. No marketing fluff, one clear next step, and the phone number shows up only when someone actually asks for help.
It protects your list
When someone asks to stop, the agent confirms removal in one neutral sentence, pushes their address to the suppression list, and never tries to win them back. That keeps you compliant and off spam traps.
Want this running for you?
Take the file and set it up yourself, or book a free call and we wire it into your inbox for you.
Build it step by step
The real path an email takes through the flow, in order, with the exact node names on the canvas and how to set each one up.
- 1Email Trigger (IMAP) · Email Trigger
Watches the mailbox and fires when a real reply lands.
Set it up: Add an Email Trigger (IMAP) and connect your mailbox login. Set the search to unseen messages that carry an In-Reply-To or References header, so it only picks up genuine replies and skips fresh mail.
- 2filter subject contain Re: · Filter
A cheap second check so the agent never answers a first-touch email.
Set it up: Add a Filter node that passes an item only when the subject contains "Re:". This backs up the trigger and keeps the agent from replying to a brand-new cold email as if it were a reply.
- 3structure the email content · Code
Cleans the message and pulls out the parts you need.
Set it up: Add a Code node. It strips quoted history and signatures, turns HTML into plain text, reads the sender name and email, and picks the right sending identity from the To: header. It also saves the Message-ID and References headers for threading.
- 4prepare ai prompt · Code
Builds the exact instructions the model will follow.
Set it up: Add a Code node. It assembles the system message, the user message, and a strict JSON shape, so the model knows the tone rules and the exact fields it must return.
- 5Execution Data · Execution Data
Tags the run with the reply-to address.
Set it up: Add an Execution Data node and save the reply-to email onto the run. That lets you search past runs by address later when you want to see what the agent sent someone.
- 6Message a model · OpenAI
Reads the tone and writes the draft reply.
Set it up: Add the OpenAI node set to GPT-5.2. Turn on JSON object output and set temperature to 0.4 for steady answers. It returns the sentiment, an unsubscribe true-or-false flag, the reply text, and a one-line reason.
- 7normalise the ai response · Code
The safety net that cleans up whatever the model returned.
Set it up: Add a Code node. It re-reads the JSON, falls back to a safe default if the JSON is broken, caps the word count, forces one greeting, strips any stray phone number, then adds the call-to-action exactly once and signs off the body.
- 8Switch · Switch
Splits opt-outs from normal replies.
Set it up: Add a Switch node that reads the unsubscribe flag. One output is for opt-outs, the other for everyone else. The two branches do the same steps, except only the opt-out branch adds the address to the suppression list.
- 9Get thread id · Gmail
Finds the Gmail thread this reply belongs to.
Set it up: Add a Gmail node set to look up a thread. Search by rfc822msgid using the saved Message-ID, so the reply lands inside the existing conversation. The normal branch has its own copy of this node.
- 10Reply to a message · Gmail
Sends the drafted answer back in-thread.
Set it up: Add a Gmail node set to reply. Point it at the thread from the last step, send the body from the normalise node, and use the campaign sender name. The normal branch mirrors this node.
- 11add to suppression list · HTTP Request
Genuinely removes an opt-out from future sends.
Set it up: On the opt-out branch only, add an HTTP Request that posts the sender's address to your email tool's suppression endpoint. Set your suppression URL and API key here. This is what makes an opt-out real. A polite note on its own does not remove anyone.
- 12Insert row · Data Table
Logs every action for your audit trail.
Set it up: Add a Data Table node. Write the sender, their raw reply, the AI response, the action (reply or unsubscribe), the confidence, and the model's reason. Both branches have their own copy pointed at the same table.
- 13Add label to thread · Gmail
Tags the thread as handled.
Set it up: Add a Gmail node that adds your "handled" label to the thread, so you can see at a glance which replies the agent already dealt with.
- 14Remove label from thread · Gmail
Clears the thread out of your inbox.
Set it up: Add a Gmail node that removes the INBOX label from the thread. The handled reply drops out of your inbox view and your inbox stays clean.
What made it tricky?
Three things ate most of the build time. If you rebuild this, they are where it goes wrong first.
The classification prompt
Getting one model to both read the tone and write the reply, in clean JSON with no markdown and no extra fields, took real iteration. The system prompt hard-codes the JSON shape, bans legal and medical advice, requires a greeting, and spells out each reply case. A low temperature keeps it steady from run to run.
The suppression list
An opt-out that only sends a nice note is a lie. The opt-out branch also fires an HTTP request that posts the address to the suppression endpoint, so the person is truly removed from future sends. Answered politely once is not the same as removed.
Safe auto-reply
Auto-sending is risky, so the normalise node is the safety net. It re-reads the model output, falls back to a safe default if the JSON is broken, caps the word count, and strips any stray phone number before adding the call-to-action once. The guardrails live in the code, backing up the prompt.
How do I adapt it to my own setup?
I shipped this as a template with every business value blanked out. Customizing it is mostly editing text, not rewiring nodes.
| What you change | Where it lives | Why |
|---|---|---|
| Company name and phone number | The system prompt and the normalise code node | Placeholders like YOUR_COMPANY and YOUR_PHONE_NUMBER. Find and replace them once. |
| Your sending domain and mailboxes | The structure the email content code node | Sets OUR_DOMAIN and the mailbox list so it picks the right identity to reply from. |
| Your brand voice and reply rules | The system prompt in Message a model | Change the tone, the call-to-action, and the reply cases. Keep the JSON fields the same so later nodes still read them. |
| Your suppression endpoint and key | The add to suppression list HTTP node | Point it at your own email tool so opt-outs land on the list that actually blocks future sends. |
| Your logins and log table | The IMAP, Gmail, and Data Table nodes | Connect your own IMAP and Gmail accounts and map the log to your own table columns. |
The whole customization surface is text and credentials, not rewiring. Swap the placeholders, edit the prompt to sound like you, connect your accounts, and aim the suppression call at your provider. If you want a human check, drop an approval step in front of the Gmail reply. If you would rather not tune the prompt yourself, this is exactly the kind of build you can hire an n8n expert to finish. It works nicely next to my triage and reply to Meta ad comments, which uses the same read, classify and reply idea.
Wondering what that costs? See what an n8n expert costs in 2026.
Email reply automation questions, straight answers.
How do you triage and reply to email automatically with an n8n AI agent?
I read inbound replies over IMAP, clean each message with a code node, then pass it to an AI model that returns strict JSON: a sentiment label, an unsubscribe flag, and a drafted reply. A Switch node sends opt-outs to a suppression call and everyone else to a Gmail reply, and every action is logged to a data table.
Does the n8n AI email agent send replies without me approving them?
In my build, yes, it replies on its own, which is why the guardrails matter. The prompt caps length, forces one greeting, allows the phone number only when someone asks for help, and never argues with an opt-out. If you want a human check, add an approval step before the Gmail node so drafts wait for a click.
How does the workflow handle unsubscribe and stop requests?
The model sets an unsubscribe flag when it sees stop, remove, or do-not-email intent. A code node replaces the body with a short, neutral confirmation, the Switch routes that branch to a Gmail reply, then an HTTP request pushes the address to my email tool's suppression list so no future campaign can email them again.
Which AI model does the n8n email automation use?
My template calls GPT-5.2 through the OpenAI node with JSON object output and temperature 0.4, so the answers stay consistent. Nothing is locked to one vendor. You can swap the model node for any provider n8n supports and keep the same strict-JSON contract, since every later node reads those same fields.
How does it keep replies in the same email thread?
The code node grabs the incoming Message-ID and References headers, then a Gmail node looks the thread up by rfc822msgid and replies inside it. That keeps the conversation threaded in the sender's inbox instead of arriving as a fresh, disconnected email, which is what makes the automated reply feel human.
What does the AI email agent log, and why?
Every run writes a row to an n8n data table: the sender, their raw reply, the AI response, the action taken, the sentiment confidence, and the model's one-line reason. That log is my audit trail. When a reply looks off, I read the reason field to see why the model chose that tone, then tune the prompt.
Can I adapt this n8n email automation to my own business?
Yes. Every business value is a placeholder: company name, phone number, suppression endpoint, and API key. Edit the system prompt to set your tone and rules, point the suppression call at your provider, map your own reply categories, and connect your IMAP and Gmail logins. That is the whole customization surface.
Want this running in your inbox?
30 minutes, free. Show me your outreach and reply volume, and I will tell you exactly how to wire an AI email agent for your stack, whether you build it or I do.
Keep reading.
Turn a YouTube video into a short
It pulls the transcript, writes a fresh script with AI, makes b-roll with Gemini Veo, and builds a ready-to-post 9:16 short.
Get fresh job matches every morning
It pulls jobs from many free sites into one pool and emails each person their best matches daily.
Reply to ad comments while you sleep
It sorts every comment, answers the simple ones, and sends the tricky ones to a person.
Rather have it built for you?
Skip the build. A free 30-minute call and we set this up in your stack, live in a week or two.