{"_note":"Machine-readable build plan from AgentMail. For the visual version open https://www.agentmail.to/build","kind":"blueprint","tldr":"Point an AgentMail message.received webhook at an n8n Webhook node, classify with the AI Agent node, reply in-thread via the AgentMail node.","title":"Email-driven AI agent in n8n","summary":"n8n already has the logic and the connectors, it just needs an inbox that can receive, thread and reply, which is exactly what AgentMail adds.","stack":[{"name":"AgentMail","role":"Inbox, threading, webhooks, send and reply","why":"n8n has no mailbox of its own that an agent can own"},{"name":"n8n","role":"Workflow runtime and AI Agent node","why":"Verified AgentMail node plus hundreds of connectors"},{"name":"OpenAI or Anthropic","role":"Model behind the AI Agent node","why":"Classification and reply drafting"},{"name":"Postgres or Google Sheets","role":"Record of each handled thread","why":"Auditing and dedupe by message id"}],"steps":["Create an inbox on a verified custom domain with a stable client_id.","Add a Webhook node in n8n and copy its production URL.","Create an AgentMail webhook on message.received pointing at that URL.","Verify the Svix signature in a Code node before any processing.","Feed extracted_text and thread history into the AI Agent node.","Reply with the AgentMail node, add labels like handled or needs-review."],"agentmailSetup":["POST /inboxes with client_id \"n8n-agent-v1\" and your custom domain.","Create webhook: event_types [\"message.received\"], url = n8n production webhook URL.","Add a custom delivery header plus Svix verification on the n8n side.","Use extracted_text on the event so quoted history is stripped before the model.","Reply with inboxes.messages.reply using message_id so threading holds.","Add labels handled and needs-review; filter list calls by label to avoid reprocessing."],"ideas":[],"options":[],"resources":[{"label":"AI agents for n8n","url":"https://agentmail.to/use-case/ai-agents-for-n8n","kind":"use-case"},{"label":"Webhooks overview","url":"https://docs.agentmail.to/webhooks-overview","kind":"docs"},{"label":"Verifying webhooks","url":"https://docs.agentmail.to/webhook-verification","kind":"docs"},{"label":"Reply and attachment extraction","url":"https://docs.agentmail.to/reply-extraction","kind":"docs"},{"label":"Trigger an AI agent when email arrives","url":"https://agentmail.to/blog/trigger-ai-agent-when-email-arrives","kind":"blog"}],"agentPrompt":"---\nproject: Email-driven AI agent in n8n\nbuilt_with: AgentMail\ndocs: https://docs.agentmail.to\nllms: https://docs.agentmail.to/llms.txt\n---\n\n# Goal\nBuild an n8n workflow that owns an AgentMail inbox, wakes on every inbound email through a message.received webhook, classifies the message with the AI Agent node, writes a record to a data store, and replies inside the original thread from the same address. Low-confidence cases become a draft or an escalation instead of an automatic send, so a human stays in control of edge cases.\n\n# Architecture\n- AgentMail inbox on a verified custom domain, created with a client_id so re-runs are idempotent.\n- AgentMail webhook subscribed to message.received, delivering to an n8n Webhook node production URL.\n- Code node verifies the Svix signature (svix-id, svix-timestamp, svix-signature) against the webhook secret and rejects anything else.\n- Dedupe step keyed on message_id so webhook retries do not produce a second reply.\n- AI Agent node receives extracted_text, subject, sender and thread id, returns intent, confidence and a draft reply.\n- Branch: high confidence goes to the AgentMail node reply action, low confidence creates a draft and notifies a reviewer.\n- Record of thread_id, intent and action written to Postgres or Sheets for audit.\n\n# Stack\n- AgentMail: Inbox, threading, webhooks, send and reply\n- n8n: Workflow runtime and AI Agent node\n- OpenAI or Anthropic: Model behind the AI Agent node\n- Postgres or Google Sheets: Record of each handled thread\n\n# AgentMail setup\n1. Install SDK: `pip install agentmail` / `npm i agentmail`\n2. POST /inboxes with client_id \"n8n-agent-v1\" and your custom domain.\n3. Create webhook: event_types [\"message.received\"], url = n8n production webhook URL.\n4. Add a custom delivery header plus Svix verification on the n8n side.\n5. Use extracted_text on the event so quoted history is stripped before the model.\n6. Reply with inboxes.messages.reply using message_id so threading holds.\n7. Add labels handled and needs-review; filter list calls by label to avoid reprocessing.\n\n# Build steps\n1. Create an inbox on a verified custom domain with a stable client_id.\n2. Add a Webhook node in n8n and copy its production URL.\n3. Create an AgentMail webhook on message.received pointing at that URL.\n4. Verify the Svix signature in a Code node before any processing.\n5. Feed extracted_text and thread history into the AI Agent node.\n6. Reply with the AgentMail node, add labels like handled or needs-review.\n\n# Acceptance checks\n- An email to the inbox triggers the n8n workflow within seconds, with no polling.\n- A request with an invalid Svix signature is rejected and no workflow runs.\n- A duplicate webhook delivery for the same message_id produces exactly one reply.\n- The reply lands in the original thread in the recipient's client, not as a new conversation.\n- A low-confidence message creates a draft and a reviewer notification instead of sending.\n\n# Notes\n- Generated by agentmail.to/build. Verify API details against the docs before shipping.\n","suggestions":[{"label":"Add human approval","prompt":"Add a human approval step so the n8n agent drafts replies and a person approves by email before sending"},{"label":"One inbox per client","prompt":"I run n8n workflows for multiple clients, how do I give each client its own inbox and keep the data isolated"},{"label":"Route to Slack and CRM","prompt":"Extend the n8n workflow to classify inbound sales mail, ping Slack for hot leads and log everything to HubSpot"}],"note":null,"human":"https://www.agentmail.to/build","followUp":{"method":"POST","url":"https://www.agentmail.to/api/build-chat","headers":{"Accept":"application/json","Content-Type":"application/json"},"body":{"messages":[{"role":"user","content":"How would I build an AI agent for n8n with AgentMail?"},{"role":"assistant","content":"Point an AgentMail message.received webhook at an n8n Webhook node, classify with the AI Agent node, reply in-thread via the AgentMail node.\n[blueprint] Email-driven AI agent in n8n: n8n already has the logic and the connectors, it just needs an inbox that can receive, thread and reply, which is exactly what AgentMail adds. (fit strong)\nNodes: sender=Inbound sender (source); inbox=AgentMail inbox (agentmail); trigger=n8n webhook (tool); agent=AI Agent node (agent); store=Data store (destination); reply=AgentMail node (tool); human=Reviewer (human)\nEdges: sender->inbox [inbound email]; inbox->trigger [webhook]; trigger->agent [message json]; agent->store [write record]; agent->reply [reply text]; agent->human [escalate]; reply->sender [threaded reply]\nStack: AgentMail (Inbox, threading, webhooks, send and reply); n8n (Workflow runtime and AI Agent node); OpenAI or Anthropic (Model behind the AI Agent node); Postgres or Google Sheets (Record of each handled thread)\nSteps: 1. Create an inbox on a verified custom domain with a stable client_id. 2. Add a Webhook node in n8n and copy its production URL. 3. Create an AgentMail webhook on message.received pointing at that URL. 4. Verify the Svix signature in a Code node before any processing. 5. Feed extracted_text and thread history into the AI Agent node. 6. Reply with the AgentMail node, add labels like handled or needs-review.\nAgentMail setup: POST /inboxes with client_id \"n8n-agent-v1\" and your custom domain. Create webhook: event_types [\"message.received\"], url = n8n production webhook URL. Add a custom delivery header plus Svix verification on the n8n side. Use extracted_text on the event so quoted history is stripped before the model. Reply with inboxes.messages.reply using message_id so threading holds. Add labels handled and needs-review; filter list calls by label to avoid reprocessing.\nTemplates: support-agent, sales-signal-router"},{"role":"user","content":"<your follow-up, for example: swap Slack for Teams, or: build idea 2>"}]},"note":"Send the whole history each time, up to 10 user messages. No state is kept between calls."}}