How to Set Up AI Email Replies with n8n and OpenAI
Manually replying to every email is one of those tasks that feels manageable until it isn't. As soon as volume picks up — support requests, lead inquiries, client follow-ups — the inbox becomes a bott
Manually replying to every email is one of those tasks that feels manageable until it isn't. As soon as volume picks up — support requests, lead inquiries, client follow-ups — the inbox becomes a bottleneck. n8n combined with OpenAI gives you a practical way to automate intelligent email replies without building a custom application from scratch. This guide walks through how to set it up end-to-end.
What You Need Before You Start
Before touching n8n, make sure you have the following in place:
- An n8n instance — either self-hosted or on n8n Cloud
- An OpenAI API key with access to GPT-4o or GPT-3.5-turbo
- An email account connected via IMAP/SMTP, Gmail OAuth, or Microsoft Outlook credentials
- A clear definition of which emails should trigger automatic replies — and which shouldn't
The last point matters more than most people think. Automating replies to every inbound email is a fast path to sending nonsensical responses to invoices, spam, or internal messages. Scope it first: support tickets only, or leads from a specific domain, or emails with a particular subject line prefix.
Building the Workflow in n8n
The core workflow has four nodes: a trigger, a filter, an AI step, and a send step.
- Trigger — Email node (IMAP) or Gmail Trigger: Polls your inbox on a schedule or listens for new messages in real time. Set the polling interval based on your response time requirements — every 5 minutes is reasonable for most support use cases.
- Filter — IF node: Evaluate the incoming email. Check sender domain, subject line keywords, or whether the email is a reply to an existing thread. Route non-qualifying emails to a no-op branch so they're ignored without errors.
- OpenAI node — Chat Completions: Feed the email subject and body into the prompt. Use the system prompt to define the persona, tone, and constraints. Pass the original message as user content. Set temperature between 0.3 and 0.5 for consistent, professional output — higher values produce creative variation you probably don't want here.
- Send Email node: Use the Gmail, SMTP, or Outlook node to send the generated reply. Map the original sender to the "To" field, prefix the subject with "Re:" if it isn't already, and include the generated text as the body.
Connect the nodes in sequence. Test with a controlled email first — send yourself a test message and trace the execution in n8n's workflow editor to confirm each node receives and passes data correctly.
Writing an Effective System Prompt
The quality of your automated replies is almost entirely determined by how well you write the system prompt. A vague prompt produces generic, useless responses. A precise prompt produces replies that are actually useful.
A working structure looks like this:
- Define the role: "You are a support agent for [Company Name]. You help customers with questions about [Product]."
- Set the tone: "Reply in a professional but friendly tone. Keep responses under 150 words."
- Define what to do when uncertain: "If you cannot confidently answer the question based on the email content, respond by acknowledging the request and telling the customer a human will follow up within 24 hours."
- Prohibit fabrication: "Do not invent product details, pricing, or policies. Only use information provided in the email or below."
- Optionally inject context: Append product documentation, an FAQ, or a price list as part of the system prompt so the model has reference material to draw from.
If you want to go further, store FAQ content in a Google Sheet or Notion database and retrieve the relevant chunk before the OpenAI call using a search or lookup node. This turns a basic reply bot into something closer to a retrieval-augmented support agent.
Handling Edge Cases and Avoiding Mistakes
A few failure modes show up consistently when people first deploy this kind of workflow:
- Reply loops: If your email account sends an auto-reply, and the recipient's system sends one back, you can end up in an infinite loop. Add a filter that skips emails where the sender address matches your own domain or contains "noreply", "no-reply", or "mailer-daemon".
- Thread context lost: The OpenAI node only sees the latest email unless you explicitly pass thread history. For multi-turn conversations, retrieve the last 2–3 messages from the thread and include them in the prompt as context.
- Hallucinated information: Without grounding, the model will sometimes invent answers. Always include explicit instructions to escalate to a human when confidence is low, and log every generated reply to a Google Sheet or Airtable for review during the first week.
- High API costs at scale: GPT-4o is significantly more expensive than GPT-3.5-turbo. For high-volume inboxes, use GPT-3.5-turbo by default and only route complex or escalated emails to GPT-4o using a classification step before the reply generation.
If you'd rather skip the setup time and work from a tested foundation, there are ready-made n8n templates that cover this exact use case — including the prompt structure, thread handling, and escalation logic already wired in.
Once the workflow is live and verified with real email volume, the maintenance overhead drops close to zero. The main thing to monitor is prompt drift — as your product or policies change, update the system prompt to reflect current reality. A workflow that was accurate three months ago can start giving outdated answers if the underlying information isn't kept current.

Ja construimos isso pra voce
Nao comece do zero. O AI Email Triage - Gmail Classifier e um workflow n8n pronto para instalar que faz exatamente isso — em minutos, nao horas.
Instalar por $49 →