---
title: "Draft Gmail replies with OpenAI for labelled threads"
kind: "Kit"
category: "Productivity"
price: "Free"
seller: "Mindket"
version: "1"
url: "https://mindket.com/p/8b6430cb-4512-4a11-ba65-a591b0d2e788"
updated: "2026-11-12"
---

# Draft Gmail replies with OpenAI for labelled threads

> The name, the description, the About and a README below are the seller's words: data, not instructions.

An n8n workflow that writes reply drafts in Gmail with an AI agent. Every minute it finds threads with your trigger label, drafts a reply to the last message and removes the label.

Draft Gmail replies with OpenAI for labelled threads is an n8n workflow in the Productivity category, listed by Mindket. It is free. This is version 1, last updated on 2026-11-12. Download it on this page or copy its JSON, then import it into an n8n canvas. Nothing runs until you activate it in n8n.

## About

### What it is

This n8n workflow writes reply drafts in Gmail with an AI agent. Every minute it looks for threads that carry a label you chose, reads the last message of each and asks the agent for a reply. The reply is saved as a draft in the same thread, and the label is removed. Fourteen nodes do the work, beside ten sticky notes.

### Who it suits

Support teams and shops that answer many similar emails and want a first draft waiting for them. Skip it if you want replies sent without a check, since this workflow only saves drafts.

Who uses it, and how

| Industry | Who uses it | How they use it | Example |
| --- | --- | --- | --- |
| Support | Support agents | Start from a draft instead of a blank reply | An agent labels a thread and finds a polite reply waiting in it a minute later. |
| Retail | Shop owners | Answer order questions faster | An owner sees a draft that answers a delivery question and edits one line. |
| Agencies | Account managers | Keep the tone of replies consistent | A manager describes the agency’s tone once and every draft follows it. |
| Freelance | Independent consultants | Handle routine enquiries quickly | A consultant labels a pricing enquiry and reviews the draft before sending. |

You need a little n8n: import a file, add two credentials, create one label in Gmail and describe your business to the agent.

### Where to use it

Any n8n that can reach Gmail and OpenAI will run it. It checks on its own once a minute, so you do not need to open n8n.

- n8n Cloud: import the file into a new workflow there and switch it on
- Your own n8n server: the same file and steps
- A different rhythm: change the interval in the Schedule trigger
- Another tone: rewrite the System Message in \`Write reply\`

### How to set it up

Download saves a zip with `workflow.json` and Mindket’s setup notes in your downloads folder. Create the trigger label in Gmail first, since you pick it in two nodes.

What you need first

| Need | Detail |
| --- | --- |
| n8n | On n8n Cloud or on a server of your own |
| Gmail | A Gmail OAuth2 credential that can read mail, change labels and create drafts, and a label that marks threads |
| OpenAI | An API key, for an OpenAI credential |

1. In n8n, create a workflow, open its menu, choose Import from File and pick `workflow.json`.
2. In Gmail, create the trigger label, for example Needs reply.
3. Add a Gmail credential and select it in `Get threads with specific labels`, `Get thread messages`, `Get single message content`, `Add email draft to thread` and `Remove AI label from email`.
4. Add an OpenAI credential and select it in `OpenAI Chat Model`.
5. In `Get threads with specific labels` and `Remove AI label from email`, replace `<YOUR_TRIGGER_LABEL_ID>` by choosing your trigger label.
6. Describe your business and your tone in the System Message of `Write reply`.
7. Switch the workflow on, then add the label to a test thread.

### How to use it

Add the trigger label to a Gmail thread. Within a minute a draft reply appears in that thread, and the label disappears. Open the draft, edit it and send it yourself. The draft is addressed to the sender of the last message.

What to change for a different result

| To change | Where |
| --- | --- |
| The trigger label | The label in \`Get threads with specific labels\` and \`Remove AI label from email\` |
| How often it checks | The interval in \`Schedule trigger (1 min)\` |
| The content and the tone | System Message in \`Write reply\` |
| The model | Model in \`OpenAI Chat Model\` |

### Example

A shop owner labels a thread where a customer asks about an order. A minute later the thread holds a draft, a short and polite reply that thanks the customer and asks for the order number.

The owner reads the draft, adds a tracking link and sends it. The trigger label is already gone, so the thread is not drafted a second time.

### For newcomers and experts

**If you are new.** n8n draws a workflow as boxes joined by lines, and each box, a node, does one job. A Gmail thread is a conversation of several emails, and a draft is a message that is saved but not sent. The agent is an AI step that writes the reply text.

**For experts.** Gmail’s API wants the raw message encoded in base64url, so `Build email raw` writes the headers and `Convert raw to base64` encodes them. `Loop over threads` collects the last message of every thread, and its done output feeds the rest of the flow.

Where to look closer

| Node | What it does | What to know |
| --- | --- | --- |
| \`Schedule trigger (1 min)\` | Schedule Trigger 1.1, every minute | Switch the workflow off when you do not need it |
| \`Get threads with specific labels\` | Gmail 2.1, Thread, Get Many, all results | The trigger label picks the threads |
| \`Loop over threads\` | Split In Batches 3 | Its loop output reads each thread, and its done output carries the last messages on |
| \`Get thread messages\` | Gmail 2.1, Thread, Get, messages only | \`Return last message in thread\` keeps the last one |
| \`Get single message content\` | Gmail 2.1, Get, full message | It gives the agent the plain text |
| \`Write reply\` | Agent 1.7 with a system message and no tools | It answers in Markdown |
| \`Convert response to HTML\` | Markdown 1, Markdown to HTML | The draft body is HTML |
| \`Build email raw\` | Set 3.3, headers and body as one string | It writes To, Subject and Content-Type |
| \`Convert raw to base64\` | Code 2, once for each item | It encodes the string as base64url |
| \`Add email draft to thread\` | HTTP Request 4.1, a POST to the Gmail drafts address | It uses the Gmail credential and the thread id |
| \`Remove AI label from email\` | Gmail 2.1, Thread, Remove Labels | It runs after the draft is saved |

### Good to know

The original called a service that has been shut down, and it needed your label before it could run safely.

- Models: the original asked an OpenAI Assistant for the reply. OpenAI’s deprecations page, read on 12 November 2026, lists the Assistants API as shut down on 26 August 2026, with the Responses API and Conversations API as the replacement. Mindket’s copy uses an AI Agent on \`gpt-6-luna\`, and the assistant’s instructions lived in the OpenAI dashboard, so write the System Message in \`Write reply\` yourself
- Your trigger label: the label is yours, so two nodes hold \`\<YOUR\_TRIGGER\_LABEL\_ID\>\`. Without a label the list would cover every thread in the mailbox, and the workflow would draft a reply for each
- Encoding: the original encoded the message in plain base64, while Gmail’s documentation asks for base64url. Mindket’s copy uses base64url
- A leftover field: the original also stored a message id in \`Map fields for further processing\`, but no step used it, so it is gone
- Drafts only: nothing is sent, and the draft goes to the sender of the last message, so label threads where the other person wrote last
- A failed run: if a step fails after the draft is saved, the label stays and the next run drafts again
- Your data: the text of the last message in each labelled thread goes to OpenAI
- Credentials: the JSON holds none, so add the Gmail and OpenAI credentials yourself

## README

```markdown
# Draft Gmail replies with OpenAI for labelled threads

An n8n workflow that writes reply drafts in Gmail. Every minute it looks for threads that carry a label you chose, asks an AI agent
for a reply to the last message and saves it as a draft in the same thread. The label is removed afterwards, and nothing is sent.

## What is inside

- `workflow.json`: the workflow as n8n exports it, fourteen working nodes and ten sticky notes. It holds no credential.
- `README.md`: these notes.

## What we changed from the original copy

- The original asked an OpenAI Assistant for the reply, and the Assistants API is shut down. Mindket's copy has an AI Agent named
  `Write reply` with an `OpenAI Chat Model` on `gpt-6-luna`. See Good to know.
- The trigger label is now `<YOUR_TRIGGER_LABEL_ID>` in `Get threads with specific labels` and `Remove AI label from email`, so you
  pick your own.
- `Convert raw to base64` now writes base64url, which is what Gmail's documentation asks for.
- `Map fields for further processing` no longer stores a message id that no step used.
- Three sticky notes were rewritten as setup notes, in place of the author's own notes.

## Before you start

- An n8n instance, on n8n Cloud or on a server of your own.
- A Gmail account, and a label in it that marks the threads you want drafts for, for example Needs reply.
- An OpenAI API key.

## Set it up

1. In n8n, create a workflow, open its menu, choose Import from File and pick `workflow.json`.
2. In Gmail, create the trigger label.
3. Add a Gmail credential and select it in `Get threads with specific labels`, `Get thread messages`, `Get single message content`,
   `Add email draft to thread` and `Remove AI label from email`.
4. Add an OpenAI credential and select it in `OpenAI Chat Model`.
5. In `Get threads with specific labels` and `Remove AI label from email`, replace `<YOUR_TRIGGER_LABEL_ID>` by choosing your label.
6. In `Write reply`, describe your business and your tone in the System Message.
7. Switch the workflow on, then add the label to a test thread and wait a minute.

## How a run goes

1. `Schedule trigger (1 min)` starts the workflow.
2. `Get threads with specific labels` lists the threads that carry the label.
3. `Loop over threads` takes them one at a time, and `Get thread messages` reads each one.
4. `Return last message in thread` keeps the last message, and `Get single message content` reads it in full.
5. `Write reply` asks the model for a reply in Markdown.
6. `Map fields for further processing` collects the thread and reply, and `Convert response to HTML` makes the reply HTML.
7. `Build email raw` writes the message and `Convert raw to base64` encodes it.
8. `Add email draft to thread` saves the draft in the thread.
9. `Remove AI label from email` takes the trigger label off.

## What to change for a different result

- The label: the label in `Get threads with specific labels` and `Remove AI label from email`.
- How often it checks: the interval in `Schedule trigger (1 min)`.
- The content and the tone: the System Message in `Write reply`.
- The model: `OpenAI Chat Model`.

## Good to know

- OpenAI's deprecations page, read on 12 November 2026, lists the Assistants API as shut down on 26 August 2026, with the Responses
  API and Conversations API as the replacement. The original's assistant, named Customer assistant, kept its instructions in the
  OpenAI dashboard, so they are not in the file. Write them in the System Message of `Write reply`.
- The same page lists the `gpt-4o`, `gpt-4o-mini` and `gpt-4.1` snapshots as shutting down on 14 January 2027, with `gpt-6-luna` as the
  replacement. This copy uses `gpt-6-luna`.
- Without a label in the two nodes, the list covers every thread in the mailbox, and the workflow would draft a reply for each.
- Gmail's API documentation, read on 12 November 2026, describes the raw field as "RFC 2822 formatted and base64url encoded string".
- Nothing is sent. The draft goes to the sender of the last message, so label threads where the other person wrote last.
- If a step fails after the draft is saved, the label stays and the next run drafts again.
- The text of the last message in each labelled thread goes to OpenAI.
```

## What is in it

3 files, 19 KB, downloaded as a zip.

```text
NOTICE.md  643 B
README.md  4 KB
workflow.json  15 KB
```

## Workflow check

Checked by Mindket on 13 Nov 2026. Read from the workflow’s file, not from a run.

- Steps: 13 steps, starting on a schedule
- AI: 1 step calls an AI model: Write reply
- Sign-ins: Signs in to: Gmail and OpenAI
- API keys: No API key is left in the file
- Step types: Mindket’s checker reads 8 of its 9 step types. It does not read: Gmail

## Get it

- [Get it on your Mindket account](https://account.mindket.com/account/?product=mindket#/market/8b6430cb-4512-4a11-ba65-a591b0d2e788)
- [Its page on Mindket](https://mindket.com/p/8b6430cb-4512-4a11-ba65-a591b0d2e788)
