🔓 Unlock all 10,000+ workflows & prompts free Join Newsletter →
✅ Full access unlocked — explore all 10,000 AI workflow and prompt templates Browse Templates →
Home n8n Workflow
January 22, 2026

Gmail + OpenAI: draft replies that match your voice

Lisa Granqvist Partner Workflow Automation Expert

Your inbox doesn’t get lighter just because you’re “caught up.” You answer one email, three more show up, and suddenly you’re rewriting the same explanations with slightly different wording.

This is where Gmail OpenAI replies helps. Support leads feel it when queues spike, sales reps feel it after every demo, and founders end up doing it at night because nobody else can match the tone.

This workflow lets you label an email thread in Gmail, then OpenAI drafts a reply in that same thread, in your style, ready for review and send. Below, you’ll see how it works and what to watch out for.

How This Automation Works

The full n8n workflow, from trigger to final output:

n8n Workflow Template: Gmail + OpenAI: draft replies that match your voice

The Problem: Email Replies Steal Time (and Consistency)

Replying to email sounds simple until you’re doing it all day. You have to find the right thread, read the latest message, remember the context from earlier replies, then write something that’s accurate and still sounds like you. And if your team touches the same inbox, tone drifts fast. One reply is short and blunt, the next is overly formal, and suddenly customers think they’re talking to three different companies. Then come the rewrite loops. “Can you soften this?” “Add the policy link.” “Remove that sentence.” It’s not hard work. It’s just endless.

It adds up fast. Here’s where it usually breaks down.

  • You re-read the whole thread because the newest message doesn’t include key details.
  • Drafts get written in a rush, which means more back-and-forth edits before you can send.
  • Teams copy old templates, but they still have to personalize everything manually.
  • Important emails get missed because there’s no clean “ready for a draft” handoff step.

The Solution: Label a Thread, Get a Draft Reply in Your Voice

This n8n workflow turns “I need to reply to this” into a simple label in Gmail. On a schedule (every minute), n8n checks your inbox for threads tagged with your chosen label (for example, generate-reply). For each labeled thread, it pulls the latest message content, sends that context to your selected OpenAI Assistant, and asks it to write a reply that matches your tone. The workflow then formats the response into an email-safe draft, creates the draft inside the original Gmail thread, and finally removes the trigger label so the same conversation doesn’t get processed again. You stay in control because nothing sends automatically. You review, tweak if needed, then hit send.

The flow is simple on purpose. Gmail provides the trigger and the thread context, OpenAI produces a reply draft that sounds like you, and n8n stitches it together into a proper Gmail draft so you can approve it in seconds.

What You Get: Automation vs. Results

Example: What This Looks Like

Say you handle 20 customer emails a day that need thoughtful replies. If writing each response takes about 6 minutes between reading the thread, drafting, and rewriting, that’s roughly 2 hours daily. With this workflow, you label the thread (10 seconds), wait a minute or two for the scheduled check and AI draft, then spend maybe 1 minute reviewing and adjusting before sending. That’s about 20–30 minutes of review time instead of hours of writing from scratch.

What You’ll Need

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • Gmail to label threads and store drafts.
  • OpenAI Assistant to generate tone-matched replies.
  • OpenAI API key (get it from the OpenAI dashboard).

Skill level: Intermediate. You’ll connect accounts, choose a Gmail label, and paste credentials, plus minor testing to confirm drafts appear correctly.

Don’t want to set this up yourself? Talk to an automation expert (free 15-minute consultation).

How It Works

A scheduled inbox check runs in the background. Every minute, n8n looks for Gmail threads that have your chosen label, so you can “queue” emails for drafting just by tagging them.

The workflow grabs the right context. It retrieves messages from each thread and selects the latest email so the draft responds to what was actually said most recently, not an older message.

OpenAI writes the reply draft. The latest message is sent to your OpenAI Assistant, which generates a context-aware response that follows the tone and rules you’ve defined in that Assistant.

A real Gmail draft is created, then the label is cleared. n8n formats the response into an email-friendly body, composes the raw email payload, encodes it, creates the draft in the same thread, and removes the trigger label to avoid duplicate drafts.

You can easily modify the trigger label to match your internal workflow (for example, “needs-reply” or “draft-with-ai”) based on your needs. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Scheduled Check Trigger

Set the schedule that kicks off the automated email drafting process.

  1. Add and open Scheduled Check Trigger.
  2. Set the schedule rule to run every minute using the existing interval: {"field":"minutes","minutesInterval":1}.
  3. Connect Scheduled Check Trigger to Retrieve Labeled Threads.

If you plan to run less frequently in production, increase the interval to reduce Gmail API usage.

Step 2: Connect Gmail

Configure Gmail access to read labeled threads, fetch messages, create drafts, and remove labels.

  1. Open Retrieve Labeled Threads and keep Resource set to thread with Return All enabled.
  2. Credential Required: Connect your gmailOAuth2 credentials in Retrieve Labeled Threads.
  3. Open Fetch Message Details and set Message ID to {{ $json.id }} with Operation set to get.
  4. Credential Required: Connect your gmailOAuth2 credentials in Fetch Message Details.
  5. Open Retrieve Thread Messages and set Thread ID to {{ $json.id }} with Operation set to get and Return Only Messages enabled.
  6. Credential Required: Connect your gmailOAuth2 credentials in Retrieve Thread Messages.
  7. Open Create Draft in Thread and confirm URL is https://www.googleapis.com/gmail/v1/users/me/drafts and Method is POST.
  8. Credential Required: Connect your gmailOAuth2 credentials in Create Draft in Thread.
  9. Open Clear AI Label and set Thread ID to {{ $('Map Data Fields').item.json["threadId"] }} with Operation set to removeLabels.
  10. Credential Required: Connect your gmailOAuth2 credentials in Clear AI Label.

⚠️ Common Pitfall: Retrieve Labeled Threads currently has an empty labelIds filter. Add the label ID used to mark AI-draft candidates to avoid drafting from all threads.

Step 3: Set Up Query AI Assistant

Configure the AI assistant that generates the response content for each thread.

  1. Open Query AI Assistant and set Resource to assistant.
  2. Set Text to {{ $json.text }} and Prompt to define.
  3. Select your assistant in Assistant ID (replace [YOUR_ID] with your actual assistant).
  4. Credential Required: Connect your openAiApi credentials in Query AI Assistant.

If the assistant expects structured inputs, adjust the message content in Fetch Message Details or add a preprocessing Set node before Query AI Assistant.

Step 4: Configure Processing and Draft Creation

Map the AI response and Gmail metadata, format HTML, build the raw email, encode it, and create a draft in the original thread.

  1. In Iterate Through Threads, keep the default batch settings. Note that Iterate Through Threads outputs to both Fetch Message Details and Retrieve Thread Messages in parallel.
  2. In Select Latest Message, keep Keep set to lastItems, then connect it back to Iterate Through Threads.
  3. In Map Data Fields, map the following values:
    response{{ $json.output }}
    threadId{{ $('Fetch Message Details').item.json["threadId"] }}
    to{{ $('Fetch Message Details').item.json["from"]["text"] }}
    subject{{ $('Fetch Message Details').item.json["subject"] }}
    messageId{{ $('Retrieve Labeled Threads').item.json["id"] }}
  4. In Render HTML Response, set Mode to markdownToHtml and Markdown to {{ $json.response }}, saving to Destination Key response.
  5. In Compose Raw Email, set raw to:
    To: {{ $json.to }} Subject: {{ $json.subject }} Content-Type: text/html; charset="utf-8" {{ $json.response }}
  6. In Encode Email Base64, keep the JavaScript that sets encoded using Buffer.from($json.raw).toString('base64').
  7. In Create Draft in Thread, set JSON Body to:
    {"message":{"raw":"{{ $json.encoded }}", "threadId": "{{ $('Map Data Fields').item.json["threadId"] }}"}}
  8. Ensure Create Draft in Thread flows into Clear AI Label to remove the AI label after drafting.

⚠️ Common Pitfall: If you see “Invalid base64” errors, confirm Compose Raw Email is producing valid headers and that Encode Email Base64 is receiving $json.raw.

Step 5: Test and Activate Your Workflow

Validate that messages are drafted correctly and labels are cleared before enabling the schedule.

  1. Click Execute Workflow to run a manual test using the current labeled threads.
  2. Verify that Query AI Assistant returns a response and that Create Draft in Thread creates a draft in Gmail.
  3. Check that Clear AI Label removes the label from the processed thread.
  4. Once successful, toggle the workflow to Active to run on the schedule.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Common Gotchas

  • Gmail permissions can be picky. If drafts stop appearing, check your n8n Gmail credential scopes and reconnect the account in n8n first.
  • If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
  • OpenAI outputs will feel “fine” but not quite you unless you define voice rules. Update your Assistant instructions early, or you will be doing constant edits.

Frequently Asked Questions

How long does it take to set up this Gmail OpenAI replies automation?

About 30 minutes if your Gmail label and OpenAI Assistant are ready.

Do I need coding skills to automate Gmail OpenAI replies?

No. You’ll mostly connect accounts and choose the label and Assistant. The workflow’s “code” piece is already included for creating the Gmail draft.

Is n8n free to use for this Gmail OpenAI replies workflow?

Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in OpenAI API usage, which is usually a few cents per drafted reply depending on email length.

Where can I host n8n to run this automation?

Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.

Can I customize this Gmail OpenAI replies workflow for different labels per team?

Yes, but keep it simple. Duplicate the “Retrieve Labeled Threads” Gmail step for each label, then route each one to a different “Query AI Assistant” configuration. Common tweaks include separate Assistants for sales vs. support, stricter policies for refunds, and a different sign-off line per inbox.

Why is my Gmail connection failing in this workflow?

Most of the time it’s an expired OAuth token or missing Gmail permissions after a security update. Reconnect the Gmail credential in n8n, then confirm the label exists and the account actually has access to the threads you’re tagging. If it fails only on busy days, you may be hitting Gmail API limits, so reduce how many threads you process per run (the split-in-batches node helps). Also check that the workflow is removing the trigger label, because reprocessing the same thread can look like “something is stuck.”

How many emails can this Gmail OpenAI replies automation handle?

Practically, it handles dozens to hundreds per day for most small teams, as long as you batch threads and stay within Gmail and OpenAI rate limits. On n8n Cloud, capacity depends on your plan’s monthly executions; if you self-host, it’s mostly about server resources and API limits. If you label 200 threads and run every minute, you’ll want to cap how many are processed per run so you don’t create a backlog.

Is this Gmail OpenAI replies automation better than using Zapier or Make?

Sometimes. n8n is better when you need more control over the “draft creation” step, because this workflow uses a raw email payload and an HTTP request to create a proper thread draft. You also get batching and branching without paying per extra path. Zapier or Make can be quicker for simple triggers, but they often get awkward when you need to fetch thread messages, select the latest one, format HTML, and then draft in-thread reliably. If you’re unsure, Talk to an automation expert and describe your inbox volume and reply requirements.

Once this is running, labeling an email becomes the only “admin work” you do. The workflow drafts, you review, and your inbox stops demanding so much of your day.

Need Help Setting This Up?

Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.

Lisa Granqvist

Workflow Automation Expert

Expert in workflow automation and no-code tools.

×

Use template

Get instant access to this n8n workflow Json file

💬
Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Launch login modal Launch register modal