🔓 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: drafts, labels, and fewer misses

Lisa Granqvist Partner Workflow Automation Expert

Your inbox isn’t “busy.” It’s chaotic. Important threads get buried, you reread the same email chain three times, and the one message with the key attachment somehow disappears right when you need it.

Marketing leads feel it when approvals stall. Client-facing teams feel it when response time slips. And if you run a small business, Gmail OpenAI automation can be the difference between “on top of it” and “constantly behind.”

This workflow watches new emails, classifies them, drafts replies in your voice, labels everything cleanly, and pings you only when it’s truly urgent. You’ll see how it works, what you need, and where teams usually tweak it.

How This Automation Works

The full n8n workflow, from trigger to final output:

n8n Workflow Template: Gmail + OpenAI: drafts, labels, and fewer misses

The Problem: Email triage steals your best hours

Most inboxes fail in a very specific way. You don’t lose time on one email, you lose it in the constant context switching: read, search the thread, download an attachment, decide urgency, remember to follow up, then repeat. After a few days, you have half-labeled conversations, “I’ll reply later” messages that never get replied to, and a vague anxiety that you missed something important. The worst part is that the work feels necessary, so it’s hard to stop doing it manually.

The friction compounds. Here’s where it breaks down in real life.

  • You reread long threads just to figure out what changed since the last message.
  • Urgent emails blend in with newsletters and “quick questions,” so you check Gmail more often than you should.
  • Drafting replies eats the day because you’re starting from a blank page each time.
  • Attachments get saved inconsistently, which means searching Drive later (again) when someone asks for “that PDF.”

The Solution: AI-assisted Gmail triage that drafts and organizes

This n8n workflow acts like a quiet email assistant that never gets tired. When a new message hits Gmail, the workflow pulls the full conversation context, grabs the latest message body, and checks your existing Gmail labels so it can stay consistent with your current system. Then OpenAI classifies the email by urgency, priority, and “what should happen next” (reply, follow up, upload attachments, forward to a team, and so on). Based on that classification, it takes action: it applies the right label, marks the email as processed, and generates a context-aware draft reply that you can review in Gmail. If the message is genuinely urgent, you also get an instant Telegram alert so it doesn’t sit unseen.

The workflow starts with Gmail intake and thread retrieval. OpenAI handles classification and reply drafting with memory for better continuity. Finally, Gmail gets labeled and drafted, and attachments can be uploaded to Google Drive with duplicate checks so you don’t end up with five copies of the same file.

What You Get: Automation vs. Results

Example: What This Looks Like

Say you get about 30 meaningful emails a day. If you spend roughly 5 minutes per email to skim, decide priority, label it, and start a reply, that’s about 2.5 hours daily. With this workflow, you mostly do two things: scan the label/priority and approve or edit a draft. Call it 1 minute per email plus a few urgent pings, so around 30–40 minutes. That’s close to 2 hours back on a normal day.

What You’ll Need

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • Gmail for triggering, labeling, and saving drafts.
  • OpenAI to classify emails and draft replies.
  • OpenAI API key (get it from your OpenAI dashboard).

Skill level: Intermediate. You’ll connect credentials, paste in your label IDs, and tweak a couple of prompts for your voice.

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

How It Works

A new email arrives in Gmail. The workflow triggers on incoming messages and batches them so one busy hour doesn’t overwhelm your setup.

The thread and message content are pulled in. It fetches the conversation thread, identifies the latest message, and extracts the body so the AI isn’t guessing from a subject line.

OpenAI classifies, then routes the next action. The classifier looks at urgency, priority, and category (to reply, date-related, requires follow-up, attachments to upload, and more). A routing switch decides what happens next: draft a response, label it, upload attachments, send an urgent alert, or some combination.

Drafts, labels, and alerts land where you already work. You’ll see a prepared draft inside Gmail, classification labels applied automatically, and Telegram alerts only when the workflow flags something as urgent.

You can easily modify the categories and urgency keywords to match your business, then change where alerts go (Telegram to Slack, for example) based on your needs. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Gmail Trigger

Set up the workflow to watch your inbox and pull full email content with attachments.

  1. Add and open Gmail Intake Trigger.
  2. Set Simple to false.
  3. Set Filters → q to -from:me.
  4. Enable Options → Download Attachments to true.
  5. Set Poll Times to everyHour.

Credential Required: Connect your Gmail credentials to Gmail Intake Trigger.

Step 2: Connect Gmail Data Retrieval and Label Discovery

Pull the full thread, isolate the most recent message, and collect user-defined labels for classification.

  1. In Iterate Messages, keep default settings to batch through incoming items from Gmail Intake Trigger.
  2. Configure Fetch Conversation Thread with Resource set to thread and Thread ID to {{ $('Gmail Intake Trigger').item.json.threadId }}.
  3. Set Retrieve Latest Message ID to keep lastItems.
  4. Set Fetch Latest Message Body with Message ID to {{ $('Retrieve Latest Message ID').item.json.id }} and Simple to false.
  5. In Retrieve Gmail Labels, set Resource to label and Return All to true.
  6. In Filter User-Only Labels, keep the condition {{ $('Retrieve Gmail Labels').item.json.type }} equals user.
  7. In Aggregate User Labels, aggregate fields id and name with Merge Lists enabled.

Credential Required: Connect your Gmail credentials to all Gmail nodes (6 total), including Fetch Conversation Thread, Fetch Latest Message Body, Retrieve Gmail Labels, Generate Draft Reply, Apply Classification Label, and Flag as Processed.

Step 3: Set Up AI Classification and Parsing

Configure the language model, output parsers, and AI prompt used to classify each email.

  1. Open AI Chat Model and select model gpt-4o-mini.
  2. In Structured Result Parser, keep Schema Type set to manual and the JSON schema as provided.
  3. In Auto Correcting Parser, leave defaults; it will be linked as the output parser for AI Mail Classifier.
  4. In AI Mail Classifier, set Text to the full prompt block: =<message> {{ $('Fetch Latest Message Body').item.json.textAsHtml }} </message> <subject> {{ $('Fetch Latest Message Body').item.json.subject }} </subject> <metadata> {{ $('Fetch Latest Message Body').item.json.headers.from }} {{ $('Fetch Latest Message Body').item.json.headers.date }} </metadata> <attachments> {{ $('Gmail Intake Trigger').item.binary ? true : false }} </attachments> <categories> {{ JSON.stringify($('Aggregate User Labels').all(), null, 2) }} </categories> <current_category_labels> {{ $('Gmail Intake Trigger').item.json.labelIds }} </current_category_labels> <message_thread> {{ $('Gmail Intake Trigger').item.json.textAsHtml }} </message_thread>
  5. Ensure AI Mail Classifier has Has Output Parser enabled so it uses Auto Correcting ParserStructured Result Parser.

Credential Required: Connect your OpenAI credentials to AI Chat Model. This model is used by AI Mail Classifier and AI Reply Composer.

Auto Correcting Parser and Structured Result Parser are connected as AI output parsers for AI Mail Classifier — ensure credentials are added to AI Chat Model, not these parser nodes.

Step 4: Configure Routing, Draft Replies, and Label Actions

Route the AI decision into replies, alerts, and label application.

  1. Open Action Routing Switch and verify the rule conditions use: {{ $json.output.classification.toReply }}, {{ $json.output.classification.attachmentsToUpload }}, and {{ $json.output.classification.urgent }}.
  2. In AI Reply Composer, set Text to =Subject: {{ $('Gmail Intake Trigger').item.json.subject }} Message: {{ $('Gmail Intake Trigger').item.json.textAsHtml }}.
  3. In Generate Draft Reply, set Message to {{ $('AI Reply Composer').item.json.text.replace(/\n/g, "<br />\n") }} and Subject to {{ $('Gmail Intake Trigger').item.json.headers.subject }}.
  4. In Collect Label Identifiers, aggregate output.classification.label_ids into label_ids.
  5. In Apply Classification Label, set Label IDs to {{ $('Collect Label Identifiers').item.json.label_ids[0] }} and Message ID to {{ $('Gmail Intake Trigger').item.json.id }}.
  6. In Flag as Processed, set Label IDs to [YOUR_ID] and Message ID to {{ $('Gmail Intake Trigger').item.json.id }}.
  7. In Dispatch Urgent Alert, set Chat ID to [YOUR_ID] and keep the alert text template as provided.

Action Routing Switch routes to multiple outputs; when a message qualifies, it can trigger both reply drafting and label processing.

Credential Required: Connect your Gmail credentials to Generate Draft Reply, Apply Classification Label, and Flag as Processed.

Credential Required: Connect your Telegram credentials to Dispatch Urgent Alert.

Step 5: Configure Attachment Handling and Google Drive Storage

Verify attachments, extract files, check for duplicates, and upload to Google Drive.

  1. In Verify Attachments, keep the condition checking {{ $('Gmail Intake Trigger').item.binary }} exists.
  2. In Extract All Attachments, keep the function code that outputs all attachment binaries.
  3. Confirm parallel execution: Extract All Attachments outputs to both Search Existing Files and Merge Attachment Info in parallel.
  4. Set Search Existing Files with Query String to: {{ $('AI Mail Classifier').item.json.output.metadata.receivedDate.toDateTime().format('yyyy.MM.dd') + " - " + $('Gmail Intake Trigger').item.json.from.value[0].address + ' - ' + $('Extract All Attachments').item.json.fileName.split(".")[0] + "." + $('Extract All Attachments').item.json.fileName.split(".")[1]}} and set Return All to true.
  5. In Evaluate File Presence, keep the check that {{ $('Search Existing Files').item.json }} is not empty.
  6. In Merge Attachment Info, set Mode to chooseBranch and Use Data Of Input to 2.
  7. In Upload to Drive Storage, set Folder ID to [YOUR_ID] and keep the Name expression for standardized file naming.

Credential Required: Connect your Google Drive credentials to Search Existing Files and Upload to Drive Storage.

⚠️ Common Pitfall: If Upload to Drive Storage fails, double-check the Folder ID and that Drive permissions allow file creation in that folder.

Step 6: Test and Activate Your Workflow

Run a full test to verify classifications, drafts, labels, and uploads, then enable the workflow.

  1. Click Execute Workflow and send a test email to trigger Gmail Intake Trigger.
  2. Confirm AI Mail Classifier outputs structured JSON matching Structured Result Parser.
  3. Verify drafts appear in Gmail from Generate Draft Reply, labels are applied by Apply Classification Label and Flag as Processed, and urgent alerts are sent by Dispatch Urgent Alert.
  4. Check Google Drive to confirm files were created by Upload to Drive Storage when attachments exist.
  5. Toggle the workflow to Active for production use.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Common Gotchas

  • Gmail credentials can expire or be missing scopes. If things break, check the Gmail OAuth connection in n8n’s Credentials first, then re-test the Gmail Trigger node.
  • If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
  • Default prompts in AI nodes are generic. Add your brand voice early or you’ll be editing outputs forever.

Frequently Asked Questions

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

About an hour if your Gmail and OpenAI credentials are ready.

Do I need coding skills to automate Gmail OpenAI automation?

No. You’ll mostly connect accounts and paste in a few label IDs. The only “technical” part is tweaking the AI prompts so the drafts sound like you.

Is n8n free to use for this Gmail OpenAI automation 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 costs, which are usually a few cents per email depending on model and thread 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 automation workflow for Slack alerts instead of Telegram?

Yes, but you’ll swap the notification step. Replace the “Dispatch Urgent Alert (telegram)” node with a Slack node (or Microsoft Teams), then keep the same routing logic from the “Action Routing Switch.” Common customizations include changing urgency keywords, adding your standard sign-off in the “AI Reply Composer,” and mapping categories to your existing Gmail labels.

Why is my Gmail connection failing in this workflow?

Most of the time it’s OAuth scope or an expired token. Reconnect the Gmail credential in n8n, then re-test the Gmail Trigger and any Gmail “Get thread / Create draft / Apply label” nodes. Also check that the workflow isn’t hitting Gmail API quota if you’re processing a backlog, because that can look like random failures. Finally, make sure the label IDs you hardcoded still exist in Gmail.

How many emails can this Gmail OpenAI automation handle?

Practically, it can handle a normal small-team inbox without trouble. On n8n Cloud Starter you’re limited by monthly executions, while self-hosting has no fixed execution cap (your server is the limit). If you process hundreds of emails a day, keep an eye on OpenAI cost and Gmail API quotas, and consider batching plus stricter “urgent” rules.

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

Often, yes. This workflow uses branching logic, attachment handling, and multi-step routing that gets expensive and awkward in Zapier. n8n also gives you a self-host option, which matters if you want predictable costs. That said, if you only want “new email → send Slack message,” Zapier or Make is simpler. For anything involving drafts, labels, and classification categories, n8n is usually the calmer choice. If you want a second opinion, Talk to an automation expert.

Your inbox can stay busy without staying messy. Set this up once, then spend your attention on the emails that actually deserve it.

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