AI-Powered Gmail Classification and Contextual Draft Generator - n8n Workflow

Automate Gmail organization using this sophisticated n8n workflow. It uses Azure OpenAI and LangChain nodes for deep sentiment analysis, smart email classification, and drafting contextual replies, providing a complete n8n template for email efficiency.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Business Owners & Executives: Individuals overwhelmed by high email volumes needing automatic triage.
Support Teams: Organizations looking to classify support tickets instantly (e.g., 'call request,' 'needs reply') before human intervention.
n8n Automation Specialists: Users interested in advanced AI utilization, particularly integrating LangChain and Azure OpenAI Chat Model capabilities within an n8n node structure.
Developers: Those seeking robust n8n templates for incorporating external context (like calendar data) into AI responses.

Overview

Managing a high volume of email requires immediate classification and rapid, appropriate responses. This specialized n8n workflow solves this by providing an intelligent system that executes deep analysis on every incoming message. Using the powerful Azure OpenAI Chat Model coupled with specialized LangChain n8n node types, the system performs multi-layered sentiment analysis to categorize emails into specific labels (Spam, Important, Personal, Promotion, Call request, Needs Reply).

Crucially, for emails requiring action, the system activates an AI Agent (Draft Reply) which uses various tools, including Gmail and Google Calendar tools, to gather context. This allows the AI to generate highly relevant and customized draft replies. This comprehensive n8n solution ensures that urgent messages are flagged, non-essential mail is filtered, and necessary responses are prepared instantly, significantly reducing manual email processing time. This is a prime example of an effective AI-driven n8n template.

How it Works

This powerful n8n workflow initiates instantly upon receiving a new email, starting with the dedicated Gmail Trigger n8n node.


  1. Trigger and Input: The n8n trigger captures the new email data. A subsequent Set n8n node ($INPUTS$) prepares this data for AI consumption.

  2. Primary Classification: The data is passed to the Sentiment Analysis n8n node (powered by the Azure OpenAI Chat Model). This primary analysis categorizes the email. Based on this classification, the data is routed to specific Gmail action nodes (e.g., Spam, Personal, Important, etc.) for labeling or movement within Gmail.

  3. Secondary Importance Check: Emails classified as less critical (like 'Notification' or 'Promotion') are passed to a secondary check (important? Sentiment Analysis n8n node) to confirm if human attention is required, routing them either to the Gmail node or the Important node.

  4. Reply Requirement Check: Emails classified as Important are subjected to a needs reply? n8n node check. If no reply is needed, the n8n workflow terminates via the No Operation, do nothing n8n node.

  5. Draft Generation (AI Agent): If a reply is necessary (from the Needs Reply, Personal, or Call request branches), the core Draft Reply LangChain Agent n8n node is activated. This agent utilizes configured tools (Draft, Get emails, Google Calendar) to formulate a detailed, context-aware response.

  6. Structured Output: The AI Agent's output is parsed using the json schema n8n node to ensure a structured response, which is then used by the Write draft Gmail n8n node to create the draft in the user's inbox.

  7. Notification: Finally, the n8n workflow notifies the user via the Telegram n8n node that a new, AI-generated draft reply is ready for review.

Installation Guide

To deploy this expert n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON data and navigate to your n8n instance. Click 'New' > 'Import from JSON' and paste the code.

  2. Set Up Gmail Credentials: Configure credentials for the Gmail Trigger n8n node and all subsequent Gmail action n8n nodes (Spam, Important, Write draft, etc.). Ensure these credentials have permission to read emails, apply labels, and create drafts.

  3. Configure Azure OpenAI: You must configure the Azure OpenAI Chat Model n8n node. This requires entering your Azure OpenAI service details (API key, endpoint, and deployment name). This connection powers all the classification and drafting AI capabilities in the n8n template.

  4. Configure Telegram (Optional): Set up credentials for the Telegram n8n node if you wish to receive notifications when a draft is ready. Replace placeholder chat IDs with your own.

  5. Activate: Save the n8n workflow and activate it using the toggle switch. The Gmail trigger will now monitor your inbox.

Node Details

This advanced n8n workflow relies on several specialized n8n node types for its robust functionality:

Gmail Trigger: The essential n8n trigger that starts the automation upon detecting a new email. It initiates the entire n8n workflow.
Azure OpenAI Chat Model: Acts as the Language Model backbone for all AI operations. It connects to all LangChain n8n nodes, providing the necessary intelligence for classification and drafting.
Sentiment Analysis (LangChain n8n node): Used extensively for both primary classification (Sentiment Analysis) and secondary checks (important?, needs reply?). It determines the intent and priority of the email, routing the n8n workflow accordingly.
Draft Reply (LangChain Agent n8n node): The core response generation engine. This n8n node is configured as an Agent capable of using tools, allowing it to perform actions like retrieving related emails (Get emails) or checking appointment availability (Google Calendar) before generating a precise reply draft.
Google Calendar Tool: An n8n node used by the AI Agent to check availability, essential for emails requesting meetings or calls (Call request branch).
Write draft (Gmail n8n node): The final action n8n node responsible for creating the prepared, AI-generated response in the user's Gmail drafts folder.


  • n8n Gmail Action Nodes (Spam, Important, Personal, etc.): A series of standard Gmail n8n nodes used to apply labels, archive, or move emails based on the classification output of the LangChain Sentiment Analysis n8n node.

Related n8n Workflows

Paid

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by
Ian Dikhtiar
Ian Dikhtiar

Featured*