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
- Required Accounts
Google account (Gmail + Google Sheets) OpenAI API account Telegram Bot n8n instance (Cloud or Self-hosted)
- 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
- 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.
- 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
- Connect OpenAI
Add your OpenAI API key Ensure access to chat models and embeddings No additional configuration required
- 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.
Related Templates
AI Email Classifier & Auto-Delete for Gmail (SPAM/OFFER Cleaner)
This workflow is designed for freelancers, solopreneurs, and business owners who receive a high volume of irrelevant mes...
Generate Food Recipes from Gmail & Form Requests with Ollama & Llama 3.2
This n8n template demonstrates how to create an intelligent food recipe assistant that accepts requests via Gmail and we...
Automatic News Summarization & Email Digest with GPT-4, NewsAPI and Gmail
π° AI News Digest Agent: Auto News Summarizer & Email Newsletter Create an intelligent news curation system that automat...
π Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments