Automated Gmail Reply Drafting using OpenAI Assistant - n8n Workflow

Use this powerful n8n workflow template to automatically generate Gmail reply drafts using the OpenAI Assistant. Enhance communication speed with this advanced n8n node integration.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Individuals or small teams overwhelmed by email volume needing AI assistance.

  • Professionals requiring rapid, context-aware drafting capabilities within Gmail.

  • Users searching for robust n8n templates that integrate advanced AI models.

  • Automation enthusiasts looking to leverage the n8n node system for email management.

Overview

This powerful n8n workflow template revolutionizes email management by integrating directly with the OpenAI Assistant API. It solves the pain point of delayed responses by continuously monitoring your Gmail inbox for emails tagged with a specific 'trigger' label. Once identified, the n8n workflow extracts the message content, submits it to your customized OpenAI Assistant for drafting, and seamlessly inserts the generated text back into the thread as a draft, ready for human review and final send-off. Utilizing the n8n node structure, this automation ensures high-quality, contextual responses, saving significant time daily. This advanced n8n workflow showcases effective cloud automation and API integration.

How it Works

The operation begins with the Schedule n8n trigger, configured to run every minute.


  1. Identify Threads: The Get threads with specific labels n8n node checks Gmail for conversations tagged with the designated trigger label.

  2. Process and Extract: The workflow loops over each identified thread, extracting the content of the most recent incoming message.

  3. AI Generation: The message content is passed to the Ask OpenAI Assistant n8n node, which uses your pre-configured AI Assistant to generate a reply.

  4. Formatting: The plain text or Markdown response from OpenAI is converted into HTML using the Markdown n8n node, ensuring proper email formatting.

  5. API Preparation: Two subsequent steps (Build email raw and Convert raw to base64) structure the response into the raw RFC-standard message format required by the Gmail API, and then encode it into a base64 string.

  6. Draft Insertion: An HTTP Request n8n node calls the Gmail API to inject the base64 message into the original conversation thread as a new draft.

  7. Cleanup: Finally, the Remove AI label from email n8n node deletes the initial trigger label from the thread, marking the task complete and preventing the n8n workflow from processing it again.

Installation Guide

To deploy this expert n8n workflow template, follow these setup steps:


  1. Import the JSON: Copy the n8n workflow JSON code and paste it into your n8n instance.

  2. Gmail Credentials: Set up or select valid OAuth2 credentials for Gmail in the relevant n8n node connections (e.g., Get threads with specific labels and Remove AI label from email). These credentials must allow read access, draft creation, and label management.

  3. OpenAI Setup: Configure the OpenAI API Key credentials for the Ask OpenAI Assistant n8n node.

  4. Assistant ID: Ensure the Ask OpenAI Assistant n8n node is configured with the correct ID of your pre-trained OpenAI Assistant. This assistant must have explicit instructions for drafting email replies.

  5. Trigger Label: In the Get threads with specific labels n8n node, define the Gmail Label ID that will serve as the n8n trigger for starting the AI drafting process.

  6. Activation: After all credentials and node parameters are confirmed, activate the n8n workflow to begin automated scheduling.

Node Details

Schedule trigger (1 min): Serves as the time-based n8n trigger, ensuring the automation runs every minute to check for new emails.
Get threads with specific labels (Gmail n8n node): Queries Gmail to retrieve thread IDs that currently have a specified trigger label applied.
Get single message content (Gmail n8n node): Fetches the detailed content, subject, and sender information for the message targeted for reply.
Ask OpenAI Assistant (OpenAI n8n node): The core intelligence n8n node. It accepts the email text and uses your custom OpenAI Assistant to generate a drafted response.
Convert response to HTML (Markdown n8n node): Converts the AI-generated reply (assumed to be Markdown) into HTML format, ready for the email body.
Build email raw (Set n8n node): Constructs the plain text representation of the email draft, including necessary headers like To, Subject, and content type, using data dynamically mapped by the n8n workflow.
Convert raw to base64 (Code n8n node): A crucial step using a custom script to encode the raw email string into base64, fulfilling the Gmail API requirement for uploading draft content.
Add email draft to thread (HTTP Request n8n node): Utilizes the encoded base64 payload to call the Gmail API, successfully inserting the AI-generated reply as a draft within the relevant email thread.


  • Remove AI label from email (Gmail n8n node): Executes the final cleanup task by removing the trigger label from the thread, signaling that the n8n workflow has completed its operation on that item.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

I make videos about workflow automation and other cool things.

Featured*