Draft Email Replies Using GPT-4o-mini - n8n Workflow

Automate routine Gmail tasks with this advanced n8n workflow template. Use the n8n node for OpenAI (GPT-4o-mini) to intelligently filter unread emails and automatically draft high-quality responses for review.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Individuals who receive a high volume of email and need efficiency.

  • Professionals looking to leverage AI for initial correspondence drafting.

  • Users searching for robust n8n templates for inbox management and Gmail automation.

  • Anyone seeking an n8n workflow solution to filter and prioritize emails.

Overview

Managing a busy inbox is time-consuming, especially when routine replies must be drafted manually. This powerful n8n workflow solves this by introducing AI-powered filtration and drafting directly into your Gmail process. The system uses a specialized n8n node setup to first identify unread emails, extract context, and then employ the GPT-4o-mini model to determine if a reply is necessary. If a reply is required, the AI crafts a concise, polite response. Unlike auto-responders, this n8n workflow generates a draft within the existing thread and labels the email, ensuring you retain final oversight while drastically cutting down on drafting time. This is one of the most practical n8n templates for boosting productivity.

How it Works

This automation begins with a scheduled n8n trigger, constantly monitoring your Gmail for new, unread messages.


  1. Trigger and Fetch: The initial n8n trigger (Gmail Trigger node) polls every minute for unread emails. The Gmail node then fetches the full content of the detected message.

  2. Data Preparation: A Set n8n node extracts critical fields—the email message body, subject, sender, and the crucial thread ID—needed for subsequent actions.

  3. AI Analysis: The core 'AI Agent' n8n node (powered by GPT-4o-mini via the associated OpenAI n8n node) analyzes the message text. It follows a strict prompt instructing it to decide if the message warrants a reply (isReply: true/false). If a reply is needed, it drafts a short response (under 120 words).

  4. Structured Output: A Structured Output parser ensures the AI returns its decision and response in a predictable JSON format, making it easy for the rest of the n8n workflow to process.

  5. Conditional Check: An If n8n node checks the AI's output. If isReply is set to true, the workflow proceeds down the successful path.

  6. Draft Creation: If the condition is met, a Gmail n8n node creates a new draft reply using the AI-generated text. This draft is automatically placed within the original email thread.

  7. Labeling: Finally, a Gmail n8n node applies a specific label (e.g., 'Action') to the thread, clearly marking the email as one that has an AI-generated draft ready for user review and sending.

Installation Guide

To deploy this n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON data and import it directly into your n8n instance.

  2. Gmail Credentials: Set up or select your existing Gmail credentials for the 'Trigger on New Email', 'Get Unread Email', 'Create a draft', and 'Label Email As "Action"' n8n node connections.

  3. OpenAI Credentials: Configure your credentials for the 'OpenAI' n8n node. This specific n8n workflow uses the highly efficient gpt-4o-mini model, requiring a valid API key.

  4. Label Setup: Ensure you have a corresponding label in your Gmail account (named, for example, 'Action') and verify the label ID used in the 'Label Email As "Action"' n8n node.

  5. Activation: Once all credentials and configurations are verified, activate the n8n workflow. The Gmail n8n trigger will begin checking for new mail immediately.

Node Details

Trigger on New Email (Gmail Trigger n8n node):
Function: Starts the n8n workflow when a new unread email arrives.
Key Configuration: Polls for messages with readStatus: unread every minute.
Get Required Fields (Set n8n node):
Function: Extracts necessary data points (thread ID, message body, subject) for the AI and subsequent Gmail actions.
Key Configuration: Maps incoming JSON fields ($json.text, $json.threadId, etc.) to clean variables.
AI Agent (Langchain Agent n8n node):
Function: The core decision-making and drafting engine. Sends the email content to the OpenAI n8n node for processing.
Key Configuration: Uses a detailed prompt to define the drafting rules (polite, under 120 words) and requires the output to be strictly JSON.
OpenAI (Langchain ChatOpenAi n8n node):
Function: Executes the AI task using the specified large language model.
Key Configuration: Configured to use gpt-4o-mini for cost-effective and fast response generation.
Can AI Agent Respond? (If n8n node):
Function: Controls the flow of the n8n workflow, ensuring drafting only happens if the AI determined a reply was needed.
Key Configuration: Checks if the AI output path ($json.output.isReply) equals true.
Create a draft (Gmail n8n node):
Function: If the AI responded positively, this node creates a draft reply in Gmail.
Key Configuration: Uses the thread ID from the initial email to ensure the draft is correctly attached to the conversation.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by
Matt Chong | n8n Creator
Matt Chong | n8n Creator

Automation nerd fueled by good coffee, deep curiosity, and clean flows.

Featured*