Skip to main content

Compose reply draft in Gmail with OpenAI assistant

Workflow preview

Workflow preview
100%
Compose reply draft in Gmail with OpenAI assistant preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow uses OpenAI Assistant to compose draft replies for labeled email messages. It automatically connects the drafts to Gmail threads. You can add knowledge base to your OpenAI Assistan...

Best for

  • Ticket Management automation workflows
  • Multimodal AI automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.stickynote, n8n-nodes-base.gmail, n8n-nodes-base.httprequest, n8n-nodes-base.code, n8n-nodes-base.set, n8n-nodes-base.markdown, @n8n/n8n-nodes-langchain.openai, n8n-nodes-base.limit

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Oskar.

Original n8n.io source

1.1 Workflow description

Title
Compose reply draft in Gmail with OpenAI assistant
Workflow name
Compose reply draft in Gmail with OpenAI assistant

This workflow uses OpenAI Assistant to compose draft replies for labeled email messages. It automatically connects the drafts to Gmail threads.

💡 You can add knowledge base to your OpenAI Assistant and make your reply drafts very customized (e.g. compose response with product information in response to inquiry from customer).

🎬 See this workflow in action in my YouTube video about automating Gmail.

How it works?

The workflow is triggered at regular intervals (default: every 1 minute – you can change this value) to check for messages with a specific label (e.g., "AI").

The content of the retrieved email message is then forwarded to the OpenAI Assistant node, and a reply draft is generated. Next, the response from the Assistant is converted to HTML, and a raw message in RFC standard is composed.

💡 You can learn more about composing drafts with the Gmail API in the official Google documentation.

The raw email message (reply draft) is encoded and attached to the original thread ID. Finally, the trigger label (in this case: "AI") is removed to prevent the workflow from looping.

Set up steps

  1. Set credentials for Gmail and OpenAI.
  2. Add new label in Gmail account for messages that should be handled by the workflow (e.g. name it "AI").
  3. Select this label in the first and last Gmail nodes in workflow.
  4. Create and configure your OpenAI Assistant. Select your assistant in "OpenAI Assistant" node.
  5. Optionally: change trigger interval (by default interval is 1 minute).

If you like this workflow, please subscribe to my YouTube channel and/or my newsletter.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 2 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 3 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 6 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Sticky Note8

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 8 - Sticky Note9

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note10

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note11

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Remove AI label from email

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 12 - Add email draft to thread

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 13 - Convert raw to base64

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 14 - Build email raw

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 15 - Convert response to HTML

Type / Role
n8n-nodes-base.markdown - markdown
Config choices
Version 1

Block 16 - Map fields for further processing

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 17 - Ask OpenAI Assistant

Type / Role
@n8n/n8n-nodes-langchain.openAi - openAi
Config choices
Version 1.8

Block 18 - Get single message content

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 19 - Return last message in thread

Type / Role
n8n-nodes-base.limit - limit
Config choices
Version 1

Block 20 - Get thread messages

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 21 - Loop over threads

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 22 - Get threads with specific labels

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 23 - Schedule trigger (1 min)

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.2

3. Summary Table

Workflow Compose reply draft in Gmail with OpenAI assistant
Complexity advanced
Nodes 23
Categories Ticket Management, Multimodal AI
Author Oskar
Published 27 Mar 2024

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/2198/2198.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Compose reply draft in Gmail with OpenAI assistant do?

This workflow uses OpenAI Assistant to compose draft replies for labeled email messages. It automatically connects the drafts to Gmail threads. You can add knowledge base to your OpenAI Assistan...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Ticket Management, Multimodal AI use case.