Skip to main content

Auto-label Gmail with Ollama AI and draft smart replies

Workflow preview

Workflow preview
100%
Auto-label Gmail with Ollama AI and draft smart replies preview
Open on n8n.io

1. Workflow Overview

Who is this for This workflow is built for professionals, founders, freelancers, and anyone drowning in email who wants to automatically triage their inbox using AI — sorting emails into categories...

Best for

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

Tools used

n8n-nodes-base.stickynote, n8n-nodes-base.gmailtrigger, n8n-nodes-base.code, @n8n/n8n-nodes-langchain.agent, n8n-nodes-base.switch, n8n-nodes-base.gmail, n8n-nodes-base.googlesheets, @n8n/n8n-nodes-langchain.lmchatollama

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
Auto-label Gmail with Ollama AI and draft smart replies
Workflow name
Auto-label Gmail with Ollama AI and draft smart replies

Who is this for

This workflow is built for professionals, founders, freelancers, and anyone drowning in email who wants to automatically triage their inbox using AI — sorting emails into categories, applying Gmail labels, and generating reply drafts for important messages, all running locally with Ollama (zero paid API costs).

What this workflow does

It watches your Gmail inbox for new unread emails, uses a local AI model (Ollama) to classify each email into one of six categories (Urgent, Action Required, Follow-up, Newsletter, Automated, or Spam/Promotional), automatically applies the matching Gmail label, generates reply drafts for high-priority emails, and logs every processed email to Google Sheets for analytics.

How it works

  • Gmail Trigger watches your inbox for new unread emails at a configurable interval (default: every 30 minutes).
  • Extract Email Data parses the sender, subject, body, attachments, and metadata into clean fields — handles all Gmail node output formats.
  • AI Classifier (Ollama, running locally) analyzes the email content and returns a structured classification with category, priority, confidence score, summary, suggested action, sentiment, and a reply draft for important messages.
  • Extract Classification robustly parses the AI response (handles markdown fences, nested objects, and edge cases) and merges it with email metadata.
  • Smart Router sends each email down one of six dedicated paths based on its classification.
  • Gmail Label nodes automatically apply the correct label to each email in your inbox.
  • Reply Draft nodes create Gmail drafts for Urgent and Action Required emails — ready for you to review, edit, and send from your Drafts folder.
  • Log Entry tracks every processed email in Google Sheets with category, priority, confidence, summary, and timestamp for analytics and review.

Setup steps

  • Gmail OAuth — Connect your Google account. Grant read, modify, and compose permissions.
  • Create Gmail Labels — In Gmail, manually create these labels (the workflow applies them automatically): 🔴 Urgent 📋 Action Required 💬 Follow-up 📰 Newsletter 🤖 Automated 🚫 Spam-Promo
  • Get Label IDs — Use the Gmail API or n8n's Gmail node (operation: "Get Many Labels") to find each label's ID. Update the labelIds in each Gmail Label node with your actual IDs.
  • Ollama — Ensure Ollama is running locally (http://localhost:11434) with your preferred model pulled (e.g., ollama pull mistral). Change the model name in the Ollama Chat Model node if needed.
  • Google Sheets (optional) — Connect your Google Sheets OAuth credential and set a spreadsheet ID in the logging node. Create a sheet with columns: Date, From, Subject, Category, Priority, Confidence, Reason, Summary, Key Action, Has Reply Draft, Sentiment, Auto Archive, Gmail ID, Processed At.
  • Test — Send yourself a few test emails (urgent request, newsletter, promotional) and run the workflow manually to verify classification accuracy.

Requirements

  • Gmail account with OAuth credentials (read, modify, compose permissions)
  • Ollama running locally with a pulled model (mistral, llama3, gemma2, etc.)
  • Google Sheets account with OAuth credentials (optional, for logging)
  • n8n instance (self-hosted recommended for Ollama connectivity)

How to customize

  • Swap mistral for llama3, gemma2, deepseek, or any Ollama-compatible model.
  • Add more categories by editing the AI system prompt and adding outputs to the Switch node.
  • Change the reply draft tone (formal, casual, friendly) in the AI system prompt.
  • Add Slack or Telegram notifications for urgent emails by branching from the Label nodes.
  • Add auto-archive for newsletters and spam by adding a Gmail "Remove Labels" node (remove INBOX label).
  • Decrease the polling interval for near-real-time processing.
  • Add sender whitelist/blacklist logic in a Code node before the AI classifier.

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 - Main Overview

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

Block 2 - Sticky Note - Email Intake

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

Block 3 - Sticky Note - AI Classification

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

Block 4 - Sticky Note - Route and Label

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

Block 5 - Sticky Note - Logging

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

Block 6 - Sticky Note - Warning Labels

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

Block 7 - Sticky Note - Warning Ollama

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

Block 8 - 📥 Gmail Trigger

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

Block 9 - 🔧 Extract Email Data

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

Block 10 - 🤖 AI Email Classifier

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.1

Block 11 - 🎯 Extract Classification

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

Block 12 - 🔀 Route by Category

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 13 - 🏷️ Label: Urgent

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

Block 14 - 📝 Draft Reply (Urgent)

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

Block 15 - 🏷️ Label: Action Required

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

Block 16 - 📝 Draft Reply (Action)

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

Block 17 - 🏷️ Label: Follow-up

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

Block 18 - 🏷️ Label: Newsletter

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

Block 19 - 🏷️ Label: Automated

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

Block 20 - 🏷️ Label: Spam-Promo

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

Block 21 - 📋 Prepare Log Entry

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

Block 22 - 📊 Log to Sheet

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Block 23 - Ollama Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOllama - lmChatOllama
Config choices
Version 1

3. Summary Table

Workflow Auto-label Gmail with Ollama AI and draft smart replies
Complexity advanced
Nodes 23
Categories Ticket Management, AI Summarization
Author Tony Adijah
Published 17 Feb 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/13463/13463.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 Auto-label Gmail with Ollama AI and draft smart replies do?

Who is this for This workflow is built for professionals, founders, freelancers, and anyone drowning in email who wants to automatically triage their inbox using AI — sorting emails into categories...

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, AI Summarization use case.