Free n8n flow

AI email triage

This workflow reads replies to your emails, asks OpenAI what each person wants, and answers them in the same Gmail thread. If someone asks to be removed, it confirms, adds them to your email platform's suppression list and logs it. You need an IMAP login and a Gmail connection for the same mailbox, an OpenAI key, and an email platform with a suppression API.

You can read how I built the email triage flow.

The flow file and setup help are in #freebies on our Discord.

What it actually does

One workflow, one trigger, two paths at the end. Every step below is a real node in the file (node names in quotes).

  1. "Email Trigger (IMAP)" watches the mailbox for unread messages that carry an In-Reply-To or References header, so only replies come in. It tracks the last message id it saw.
  2. "filter subject contain Re:" keeps only messages whose subject contains "Re: ".
  3. "structure the email content" (Code) strips quoted history and signatures, pulls out the sender's name and address, and picks which of your addresses to answer from, using the To: header. Your domain and addresses go at the top of this node (OUR_DOMAIN, OUR_EMAILS).
  4. "prepare ai prompt" (Code) builds the prompt. Its list of trigger words (call, next steps, not interested, unsubscribe, stop and more) are hints for the model, not hard rules. "Execution Data" then saves the sender's address on the run, so you can search past runs by email.
  5. "Message a model" (OpenAI node, model GPT-5.2, temperature 0.4) returns strict JSON: a sentiment label and percent, an unsubscribe true or false, the reply text and a one-line reason. The prompt keeps normal replies to 2 to 4 sentences and opt-out replies to 1 or 2, skips any pitch for "not interested", and only adds your phone number when someone asks for help.
  6. "normalise the ai response" (Code) parses that JSON, merges it with the email fields and lays the reply out with line breaks and your help line.
  7. "Switch" sends each email down the unsubscribe path or the normal reply path.
  8. Unsubscribe path: find the Gmail thread by message id, reply in the thread with a short confirmation, POST the address to your ESP suppression endpoint, insert a row in the n8n Data table, add your opt-out label and remove the thread from the inbox.
  9. Normal path: find the thread, reply in it, insert a row in the Data table, add your "replied" label and remove the thread from the inbox.

It sends replies straight away. There is no approval step in this file, so test it on a spare inbox first.

Wiring: "structure the email content" has to connect to "prepare ai prompt". This file already includes that wire. If it is missing after import, drag it, or nothing reaches the AI step.

What you connect

The file is also published as this flow in the n8n template gallery.

  • IMAP credential for the mailbox you want to watch.
  • Gmail OAuth2 credential for the same mailbox. The thread lookup, replies and labels all use Gmail, so in practice this is a Gmail or Google Workspace inbox.
  • OpenAI credential. The file picks GPT-5.2. Any chat model your account has will do.
  • An email platform (ESP) with a suppression list API. The file has a placeholder URL (your-esp-api-host.com/...) and YOUR_ESP_API_KEY. Change the URL to your provider's format.
  • An n8n Data tablefor the log (the file calls it "Email replies"). Columns mapped: ai_response, reply, user, action, confidence, sender, subject, ai_reasoning, Product. Data tables arrived in n8n 1.113.1, so use that version or newer.
  • Two Gmail label ids, one for opt-outs (YOUR_GMAIL_LABEL_ID) and one for replied threads (YOUR_GMAIL_LABEL_ID_2).
  • Placeholders to replace: YourCompany in the prompt, YOUR_PHONE_NUMBER (prompt and help line), OUR_DOMAIN and OUR_EMAILS in the code node, YOUR_DATA_TABLE_ID, YOUR_N8N_PROJECT_ID.
  • Cloud or self-hosted: both work. This file uses standard n8n credentials and no $env.
  • The workflow settings name an error workflow placeholder (YOUR_ERROR_WORKFLOW_ID). Set your own error workflow or clear the setting.

How to use it

Four steps. The file in #freebies is rup-ai-email-triage.json.

1

Get the file

Join Discord and open #freebies. The flow file and setup help are there.

2

Import into n8n

In n8n, create a new workflow, open the three-dot menu, choose Import from File and pick the JSON from #freebies. Credentials are not in the file, so nodes that need one will show a warning until you connect it.

3

Connect what it asks for

Add the IMAP, Gmail and OpenAI credentials, create the Data table and the two Gmail labels, then replace the ESP URL, API key and the YOUR_... placeholders. Connect "structure the email content" to "prepare ai prompt" if it is not connected.

4

Run it

Send a test reply to the watched mailbox from another address and run the workflow once. You should see a reply land in the thread and a new row in the Data table. Turn the workflow on when you are happy with the tone.

Questions

What does the AI email triage flow do?

It reads replies to your emails, uses OpenAI to work out whether each person wants help, is not interested or wants to opt out, and answers in the same Gmail thread. Opt-outs are confirmed, sent to your email platform's suppression list and logged in an n8n Data table.

Does it send replies automatically or save drafts?

It sends them. The Gmail node replies in the thread as soon as the model answers, so test on a spare inbox and tune the prompt before pointing it at real contacts. If you want a person to check first, change the reply step to create a Gmail draft instead.

How does it handle unsubscribe requests?

When the model marks an email as an opt-out, the flow sends a one or two line confirmation with no pitch, posts the sender's address to your ESP's suppression endpoint, logs the action and moves the thread out of the inbox under an opt-out label.

Will it reply to every email in my inbox?

No. The IMAP trigger only picks up unread messages with reply headers (In-Reply-To or References), and a filter keeps only subjects that contain "Re: ". New cold emails and newsletters are skipped, and handled threads are labelled and archived so they are not picked up again.

Which accounts do I need to run it?

You need an IMAP login and a Gmail OAuth2 connection for the same mailbox, an OpenAI API key, and an email platform with a suppression list API. The log lives in an n8n Data table, so no extra database is needed.

Does it work on n8n Cloud?

Yes. It uses standard n8n credentials rather than environment variables, so it runs on n8n Cloud or self-hosted n8n. You need a version with Data tables, which arrived in n8n 1.113.1.

A small note

Goat O Mate is a community of builders shipping marketing and AI automations together.

Session 1 is coming soon. Join the Discord to hear first. We set up n8n together and ship a first AI automation.

Join Discord