Automated Email Classification and Telegram AI Assistant - n8n Workflow

Build an automated email assistant using this powerful n8n workflow. Classify new emails with Azure OpenAI, log data in Google Sheets, and interact with your mail list via a Telegram bot agent.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Users experiencing email overload who need instant alerts for critical messages.

  • Developers or power users seeking advanced n8n templates integrating LLMs and cloud services.

  • Professionals needing a conversational interface (like Telegram) to manage tasks tracked in Google Sheets.

  • Anyone looking to deploy an interactive AI agent using n8n and Azure OpenAI.

Overview

This sophisticated n8n workflow addresses email management fatigue by automating the process of classification, logging, and notification. It acts as a personal email assistant, ensuring critical communications (like security alerts or personal messages) result in immediate Telegram notifications. Unlike standard filters, this system uses an Azure OpenAI model for intelligent classification via the E-Mail Text Classifier n8n node, logging all critical mail details into Google Sheets with a 'NOT CHECKED' status. Furthermore, the second half of the n8n workflow sets up a fully interactive AI Agent accessible via a Telegram n8n trigger. Users can chat with the bot, review their unread email list, and even instruct the agent to update the status of emails in Google Sheets. This highly functional n8n workflow demonstrates complex integration between messaging, databases, and cutting-edge AI services.

How it Works

The overall n8n workflow operates in two distinct, yet interconnected, paths:

Part 1: Real-Time Email Classification


  1. Email Trigger (IMAP): This n8n trigger starts the process whenever an UNSEEN email is detected in the connected mailbox.

  2. Information Retrieval: The workflow first fetches the user’s Telegram chat ID from a Google Sheet (using the Get User ID n8n node) and extracts core details like subject, sender, and date via the Mail Information (Set) n8n node.

  3. Validation: An If Null n8n node ensures all critical mail details are present before proceeding.

  4. AI Classification: The E-Mail Text Classifier n8n node, powered by Azure OpenAI, categorizes the email into predefined groups (Security, Personal, Updates, Advertisement, Unimportant).

  5. Conditional Alerting: Depending on the category, the n8n workflow sends targeted alerts via Telegram (for Security, Personal, and Updates).

  6. Logging: For categorized emails requiring follow-up, the Append Mail Details Google Sheets n8n node logs the subject and sets the initial status to 'NOT CHECKED'.

Part 2: Interactive AI Agent Management


  1. Telegram Trigger: This second n8n trigger activates the second path when the user sends a message to the bot.

  2. User ID Logging: The Append User ID n8n node logs the user's chat ID for future notifications in Part 1.

  3. Data Retrieval: The Get E-Mails Google Sheets n8n node retrieves all emails currently marked as 'NOT CHECKED'.

  4. Data Preparation: The data is aggregated and set into a single item, which is formatted as input data for the AI Agent.

  5. AI Agent Execution: The core AI Agent n8n node (leveraging Azure OpenAI and conversation Memory) processes the user's request, referencing the list of unread emails. Crucially, this agent has access to the Update Status Google Sheets n8n node tool, allowing the user to conversationaly mark emails as checked.

  6. Response: The Reply To User n8n node sends the AI Agent's response back to the user via Telegram.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and import it directly into your n8n instance.

  2. Credentials Setup: You must configure four primary credentials for this n8n workflow:

IMAP Email: Connect your email account. Note that this often requires generating an app-specific password (especially for Gmail) rather than your standard password.
Google Sheets OAuth2: Set up Google Cloud API access to enable Google Sheets operations. Ensure the API is enabled and OAuth credentials are configured for use with the Google Sheets n8n node.
Azure Open AI (or equivalent): Configure your AI service credential, specifying the preferred model (e.g., gpt-4o-mini).
Telegram API: Create a Telegram Bot via BotFather to obtain the access token required for the Telegram n8n node.

  1. Google Sheet Preparation: Create the two required Google Sheets documents mentioned in the notes: one for maildata (containing 'E-Mail Subject' and 'Status' columns) and one for useridsmailassistant (containing the 'telegram_id' column).

  2. Initial Run: Run the workflow once. Send a message to your Telegram bot to trigger Part 2, which will automatically store your chat ID, allowing the n8n workflow to send notifications in Part 1.

Node Details

Email Trigger (IMAP): The initial n8n trigger. It monitors the specified email account for new, unread (UNSEEN) messages.
Google Sheets (Get User ID/Get E-Mails/Append Mail Details/Append User ID): Multiple instances of this n8n node manage data persistence. They are crucial for storing the user's Telegram ID, retrieving 'NOT CHECKED' emails, and logging new email subjects.
E-Mail Text Classifier (Langchain): This uses an Azure OpenAI language model (gpt-4o-mini) to analyze the email subject and context to assign a category (Security, Personal, Updates, etc.).
AI Agent (Langchain): The conversational core, driven by an Azure OpenAI LLM. It processes user requests from Telegram. This powerful n8n node maintains conversation context via the Memory n8n node.
Google Sheets Tool (Update Status): Integrated as a tool for the AI Agent n8n node, allowing the AI to execute specific database operations—namely, updating the 'Status' column in the Google Sheet based on user instructions.
If (If Null): A flow control n8n node that ensures the extracted mail data is not empty before proceeding to the classification step.


  • Telegram (Send Security Message/Send Personal Message/Reply To User): These n8n nodes handle all outgoing communications, sending alerts or conversational responses back to the user.

Related n8n Workflows

Free

Nodes: 14 Nodes
Updated: December 26 2025
View all
Created by
Meelioo
Meelioo

Delusional of 5 years!🎉🎉

Featured*