How to build an Email AI Agent with n8n - Step by Step

:hammer_and_wrench: Video notes & templates (free): Lead Form
:robot: Try n8n for free: AI Workflow Automation Platform & Tools - n8n

Build an AI email agent in n8n that automatically categorizes incoming emails, adds Gmail labels, and drafts personalized responses.

This tutorial demonstrates how to create an AI-powered email management system using n8n workflows. The agent automatically processes incoming emails, categorizes them with appropriate labels, and generates draft responses based on your business information, eliminating hours of manual email handling.

The workflow begins with the Gmail Trigger node, which monitors your inbox for new messages. By disabling the “Simplify” option, you ensure the AI receives the complete email text for accurate processing. When an email arrives, the trigger initiates the entire automation sequence.

A crucial component is the knowledge base, which provides the AI with context about your business, products, pricing, and policies. Using n8n’s built-in Data Tables feature, you can store all this information directly within the platform and retrieve it dynamically during workflow execution. This ensures the AI generates accurate, contextually appropriate responses.

The workflow also fetches all available Gmail labels using the Gmail “Get Many” action and combines them with an Aggregate node. This provides the AI with a complete list of categorization options, allowing it to intelligently assign the most appropriate label to each incoming email.

At the core of the automation is the AI Agent node, configured with a detailed prompt that defines its role as an email assistant. Connected to an OpenAI Chat Model and equipped with three tools—Telegram for notifications, and two Gmail tools for adding labels and creating drafts—the agent autonomously processes emails, categorizes them, and generates professional responses. Dynamic fields are set to be determined by the model, while static fields pull data from the trigger node using expressions.

Once configured and tested, the workflow runs automatically whenever new emails arrive. The AI processes each message, applies the appropriate label, drafts a response based on your knowledge base, and sends you a Telegram notification with a direct link to review the draft. This complete automation transforms email management from a time-consuming task into an efficient, AI-assisted process.

:date: Book a Free Consultation: Book a Call - SmoothWork
:e_mail: [email protected]

1 Like

solid tutorial, the draft-first approach is definitely the right call before handing off full autonomy. couple things we found useful running this pattern for clients:

for the knowledge base: data tables work fine for small static stuff, but once youre dealing with larger or frequently updated info, pulling from qdrant or a notion db gives noticeably better retrieval. not a dealbreaker at small scale tho.

also worth having the ai flag emails it’s unsure about rather than always drafting — contracts, complaints, anything legal. a simple confidence check in the system prompt works well for this.

we deploy similar setups for clients at Noyra-X, and the trust-building phase you mentioned is real. starting with drafts is almost always the right first step before going fully autonomous.