Compose reply draft in Gmail with OpenAI Assistant n8n Workflow Template

n8n workflow template · 13 nodes · Gmail

Compose reply draft in Gmail with OpenAI Assistant is a free n8n workflow template that runs on a schedule and works with Gmail and OpenAI. It has 13 nodes, 1 of them AI nodes (OpenAI). The notes inside the workflow say: “Run the workflow in equal intervals and check for threads with specific labels (trigger labels).” To run it, you add your own credentials for Gmail OAuth2 and OpenAI API.

At a glance

Trigger
Schedule Trigger (Schedule trigger (1 min))
Nodes
13
Apps
Gmail and OpenAI
AI nodes
1
Credentials
2 types
Category
Email automation

Apps and integrations

  • Gmail
  • OpenAI

Node types used

  • Code
  • HTTP Request
  • Gmail
  • Schedule Trigger
  • Edit Fields (Set)
  • Markdown
  • OpenAI
  • Loop Over Items
  • Limit

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Schedule trigger and get emails

Run the workflow in equal intervals and check for threads with specific labels (trigger labels).

Return message content

Retrieve content of the last message in the thread.

Get last message from thread

Return all messages for a single thread and pass for further processing only the last one.

Generate reply

Transfer email content to OpenAI Assitant and return AI-generated reply.

Create HTML message

Convert incoming Markdown from OpenAI Assistant into HTML content.

Build and encode message

Create raw message in RFC standard and encode it into base64 string (please see Gmail API reference for more details).

Insert reply draft

Add reply draft from OpenAI Assistant to specific Gmail thread.

Remove label

Delete trigger label from the Gmail thread.

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Reply draft with OpenAI Assistant

This workflow automatically transfers content of incoming email messages with specific labels into OpenAI Assitant and returns reply draft. After draft is composed, trigger label is deleted from the thread.

Please remember to configure your OpenAI Assistant first.

Note

  1. Complete video guide for this workflow is available on my YouTube.
  2. Remember to add your credentials and configure nodes (covered in the video guide).
  3. If you like this workflow, please subscribe to my YouTube channel and/or my newsletter.

Thank you for your support!

Nodes in this workflow

The 13 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. Convert raw to base64 (Code)
  2. Add email draft to thread (HTTP Request)
  3. Remove AI label from email (Gmail)
  4. Schedule trigger (1 min) (Schedule Trigger)
  5. Map fields for further processing (Edit Fields (Set))
  6. Convert response to HTML (Markdown)
  7. Build email raw (Edit Fields (Set))
  8. Get threads with specific labels (Gmail)
  9. Ask OpenAI Assistant (OpenAI)
  10. Loop over threads (Loop Over Items)
  11. Get thread messages (Gmail)
  12. Return last message in thread (Limit)
  13. Get single message content (Gmail)

Credentials you need

  • Gmail OAuth2 – used by Add email draft to thread, Get single message content, Get thread messages and Get threads with specific labels and others
  • OpenAI API – used by Ask OpenAI Assistant

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us