Analyze, classify, and summarize Gmail with OpenAI RAG and Google Sheets
Analyze, classify, and summarize Gmail with OpenAI RAG and Google Sheets
๐ง Analyze, classify, and summarize emails using RAG (automatic taxonomy learning)
This workflow automatically reads incoming Gmail messages, analyzes them using AI with a retrieval-augmented
classification system (RAG), organizes emails into structured categories, stores results in Google Sheets,
and even generates an audio summary sent directly to Telegram.
โ๏ธ How It Works
The workflow creates an intelligent email processing pipeline combining Gmail, OpenAI, vector embeddings,
and Google Sheets to continuously learn and improve email categorization accuracy.
Email Trigger
The workflow starts automatically whenever a new email arrives in Gmail using the Gmail Trigger node.
Email Extraction & Cleaning
The full email content, sender information, subject, and timestamp are retrieved and normalized.
HTML formatting is removed so the AI receives clean text data.
Knowledge Base Loading (RAG)
Email tagging examples stored in a Google Sheets document are loaded and converted into embeddings.
These examples act as the official taxonomy for categories and subcategories.
Vector Store Creation
The workflow builds an in-memory vector database containing historical tagging samples.
This allows semantic similarity search during classification.
AI Analysis Agent
An OpenAI-powered AI Agent performs multiple tasks in a single step:
Summarizes the email (short paragraph)
Creates a one-line short message
Classifies the email using retrieved vector examples
Extracts keywords
Assigns confidence score
Detects whether a new category or subcategory was created
The agent strictly prioritizes retrieved taxonomy examples to maintain consistent labeling.
Structured Data Storage
Processed email data โ including summary, category, keywords, and metadata โ is appended to a Google Sheets log,
creating a searchable email intelligence database.
Self-Learning Taxonomy
If the AI determines a new category or subcategory is required:
The new label is automatically added to the tagging samples sheet
An admin notification is sent via Telegram
This allows the system to evolve over time.
Audio Summary Generation
The summarized email text is converted into speech using OpenAI audio generation.
Telegram Notification
The generated audio summary is automatically delivered to Telegram, allowing quick email review without reading.
๐งฉ Features
โ
Fully automated Gmail monitoring
โ
Retrieval-Augmented Generation (RAG) email classification
โ
Consistent taxonomy enforcement via vector similarity
โ
Automatic keyword extraction & confidence scoring
โ
Self-updating category knowledge base
โ
Google Sheets email database
โ
AI-generated voice summaries
โ
Telegram admin notifications
โ
Continuously improving classification accuracy
๐ Setup Steps
1. Required Accounts
Google account (Gmail + Google Sheets)
OpenAI API account
Telegram Bot
n8n instance (Cloud or Self-hosted)
2. Configure Credentials in n8n
Create the following credentials inside n8n:
Gmail OAuth2 โ used by Gmail Trigger and message retrieval
Google Sheets OAuth2 โ for email storage and taxonomy dataset
OpenAI API โ for embeddings, AI analysis, and audio generation
Telegram API โ for sending notifications and audio summaries
3. Prepare Google Sheets
Sheet 1 โ Email Log
date
email
name
subject
summarized text
category
subcategory
keywords
Sheet 2 โ Tagging Samples (Knowledge Base)
id
subject
email_text
category
subcategory
keywords
This sheet acts as the classification training reference used by the vector store.
4. Configure Telegram
Create a Telegram bot using BotFather
Copy the bot token into n8n credentials
Replace the chatId value with your Telegram user or group ID
5. Connect OpenAI
Add your OpenAI API key
Ensure access to chat models and embeddings
No additional configuration required
6. Activate the Workflow
Enable the workflow
Send a test email to your Gmail inbox
Verify that:
Email appears in Google Sheets
Categories are assigned
Audio summary arrives in Telegram
๐ก Recommended Usage
Email triage automation
Customer support inbox classification
Sales lead categorization
Personal productivity systems
AI-assisted knowledge management
๐ง Architecture Notes
This workflow uses a Retrieval-Augmented Generation (RAG) pattern inside n8n by combining
Google Sheets as a lightweight knowledge base with an in-memory vector store.
Instead of relying purely on model reasoning, classification decisions are grounded
in previously approved examples, producing stable and explainable categorization.
Over time, the workflow becomes smarter as new categories are automatically added,
effectively turning your inbox into a continuously learning AI system.