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)

  1. 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

  1. 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.

  1. 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

  1. Connect OpenAI

Add your OpenAI API key Ensure access to chat models and embeddings No additional configuration required

  1. 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.

0
Downloads
0
Views
8.92
Quality Score
intermediate
Complexity
Author:Amirhosein Zahedi(View Original β†’)
Created:3/4/2026
Updated:3/4/2026

πŸ”’ Please log in to import templates to n8n and favorite templates

Workflow Visualization

Loading...

Preparing workflow renderer

Comments (0)

Login to post comments