AI-Powered Gmail Email Classifier & Labeler
Overview
This workflow automatically monitors your Gmail inbox for new emails, retrieves the full email content, and uses an AI agent powered by Anthropic's Claude to classify each email into a predefined Gmail label. It also checks prior email history with the sender to improve classification accuracy. Finally, it applies the chosen label to the email, helping you organize your inbox without manual effort.
How It Works
- Gmail Trigger — Polls Gmail every minute for new emails (OAuth2).
- Gmail — Fetches the full email details (headers, body, etc.) using the message ID from the trigger (OAuth2).
- AI Agent — Orchestrates the classification process. It uses the Anthropic Chat Model as its language model and the Structured Output Parser to extract the label ID. The agent also has access to two Gmail tools to check prior email history.
- Anthropic Chat Model — The LLM (Claude Sonnet 4) that analyzes the email content and history to decide the best label (API Key auth).
- Structured Output Parser — Ensures the AI's response is a valid JSON object containing the label ID (No auth).
- Get Email — A Gmail tool used by the AI agent to search for prior emails from the sender (OAuth2).
- Check Sent — A Gmail tool used by the AI agent to check if the user has previously sent emails to the sender (OAuth2).
- Gmail1 — Applies the chosen label to the original email (OAuth2).
Node Details
- Gmail Trigger (OAuth2) — Polls Gmail every minute for new messages. No filters are set, so it watches the entire inbox.
- Gmail (OAuth2) — Uses the
getoperation to retrieve the full email object bymessageId. Thesimpleoption is disabled to get the raw JSON. - Anthropic Chat Model (API Key auth) — Configured to use the
claude-sonnet-4-20250514model with default options. - AI Agent (No auth) — Contains a detailed system message that instructs the AI to classify emails into one of six labels (To Respond, FYI, Comment, Notification, Meeting Update, Marketing) based on content, headers, and prior email history. It uses the
textinput "Run the task." and has an output parser attached. - Structured Output Parser (No auth) — Expects a JSON schema with keys
labelandlabel ID. This forces the AI to output a clean JSON object. - Get Email (OAuth2) — Gmail tool that searches for emails from the sender using the
from:query. It returns all matching emails (no limit). - Check Sent (OAuth2) — Gmail tool that searches for emails sent to the sender in the
SENTfolder, using theto:query. - Gmail1 (OAuth2) — Uses the
addLabelsoperation to apply the label ID returned by the AI agent to the original email.
Setup Instructions
- Gmail OAuth2 Credentials — You need a Google Cloud project with the Gmail API enabled. Create OAuth2 credentials (Desktop app or Web application) and add them in n8n under Credentials > Google. The workflow uses OAuth2 for all Gmail nodes.
- Anthropic API Key — Sign up at Anthropic and generate an API key. Add it in n8n under Credentials > Anthropic.
- Gmail Labels — The workflow expects specific label IDs (e.g.,
Label_5151750749488724401for "To Respond"). You must create these labels in your Gmail account and note their IDs. Alternatively, you can modify the system message in the AI Agent node to use your own label names/IDs. - Activate the workflow — Once credentials are set and labels exist, activate the workflow. It will start polling Gmail and classifying new emails.
Use Cases & Variations
- Personal Inbox Zero — Automatically sort newsletters, notifications, and actionable emails into separate folders.
- Sales Pipeline Management — Classify incoming leads as "To Respond" or "Marketing" based on prior contact.
- Support Ticket Triage — Route customer emails to appropriate labels based on content and history.
- Custom Labels — Modify the AI agent's system prompt to use your own set of labels (e.g., "Urgent", "Read Later", "Archive").
- Integration with Other Tools — After labeling, you could add nodes to send Slack notifications, create tasks in Notion, or log to a spreadsheet.
Workflow JSON
{
"id": "uf6t5qhnQMgilteE",
"meta": {
"instanceId": "[REDACTED_INSTANCE_ID]",
"templateCredsSetupCompleted": true
},
"name": "Email Manager",
"tags": [
{
"id": "[REDACTED_TAG_ID]",
"name": "Personal Assistant",
"createdAt": "2025-05-28T13:58:43.876Z",
"updatedAt": "2025-05-28T13:58:43.876Z"
}
],
"nodes": [
{
"id": "5e01a927-caf7-41ad-aca7-d7504e313564",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-20,
-60
],
"parameters": {
"filters": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"id": "credential-id",
"name": "gmailOAuth2 Credential"
}
},
"typeVersion": 1.2
},
{
"id": "a8644856-a8bf-49de-84a7-3fd9f93550d3",
"name": "Gmail",
"type": "n8n-nodes-base.gmail",
"position": [
200,
-20
],
// ... truncated (copy to see full JSON)How to Import This Workflow
- 1Copy the workflow JSON above using the Copy Workflow JSON button.
- 2Open your n8n instance and go to Workflows.
- 3Click Import from JSON and paste the copied workflow.
Don't have an n8n instance? Start your free trial at n8nautomation.cloud
Related Templates
YouTube Video Summarizer with Telegram Notification
High-Level Summary This workflow automatically processes YouTube videos by fetching their transcripts, generating a structured AI-powered summary using OpenAI's GPT-4o-mini, and sending the summary along with video metadata to a Telegram chat. It is triggered via a webhook, making it easy to integrate with other tools or services (e.g., a browser extension, a form, or another automation). The workflow is ideal for content curators, researchers, or teams who want to quickly digest video content without watching the full video. Workflow Steps Webhook — Receives an incoming HTTP POST request containing a YouTube URL in the request body. This is the entry point of the workflow. (No auth) Get YouTube URL (Set node) — Extracts the field from the incoming webhook payload and stores it as a string variable for downstream use. (No auth) YouTube Video ID (Code node) — Runs a JavaScript function that parses the YouTube URL using a regex pattern to extract the 11-character video ID (supports both and formats). (No auth) Get YouTube Video (YouTube node) — Uses the extracted video ID to fetch video metadata (title, description, etc.) from the YouTube Data API v3. (OAuth2 — requires a Google Cloud project with YouTube Data API enabled) YouTube Transcript (Community node: ) — Fetches the transcript/captions for the video. This node requires the video ID (passed from the previous step). (No auth — uses public YouTube captions) Split Out (SplitOut node) — Splits the transcript array into individual items so each text segment can be processed separately. (No auth) Concatenate (Summarize node) — Concatenates all transcript text segments into a single string, separated by spaces, to prepare the full transcript for analysis. (No auth) gpt-4o-mini (OpenAI Chat Model node) — Configures the OpenAI language model (GPT-4o-mini) that will be used for summarization. (API Key auth — requires an OpenAI API key) Summarize & Analyze Transcript (LLM Chain node) — Sends the concatenated transcript to the GPT-4o-mini model with a detailed prompt asking for a structured summary with headers, bullet points, bold terms, and tables. The output is a markdown-formatted analysis. (No auth — uses the model configured in the previous node) Response Object (Set node) — Assembles the final output object containing: - : The AI-generated summary text - : An empty array (placeholder for future use) - : The video title from YouTube metadata - : The video description from YouTube metadata - : The YouTube video ID - : The original YouTube URL from the webhook (No auth) Respond to Webhook — Sends the assembled response object back to the original webhook caller (e.g., a browser extension or app). (No auth) Telegram — Sends a message to a specified Telegram chat containing the video title and the YouTube URL. (API Key auth — requires a Telegram Bot Token and chat ID) Setup Instructions To use this workflow, you will need the following accounts and credentials: OpenAI Account: Create an account at platform.openai.com and generate an API key. Add this as a credential in n8n under "OpenAI". Google Cloud Project: Enable the YouTube Data API v3 in your Google Cloud Console, create OAuth 2.0 credentials (Desktop app type), and add them in n8n under "YouTube OAuth2 API". Telegram Bot: Create a bot via @BotFather on Telegram to get a Bot Token. Find your chat ID (e.g., by messaging your bot and visiting ). Add the token as a credential in n8n under "Telegram API". Webhook URL: After activating the workflow, copy the production webhook URL (e.g., ). You will send POST requests to this URL with a JSON body like . Use Cases and Variations Content Curation: Automatically summarize long conference talks, tutorials, or webinars and share them with your team on Telegram. Research Assistant: Collect video transcripts and AI summaries for later reference or database storage. Browser Extension Integration: Pair this workflow with a browser extension that sends the current YouTube URL to the webhook when clicked. Variations: - Replace Telegram with Slack, Discord, or email notifications. - Store summaries in a Google Sheet or Airtable for a searchable archive. - Add a filter to skip videos shorter than a certain duration. - Use a different LLM (e.g., Claude, Gemini) by swapping the OpenAI node. - Add error handling to notify you if a video has no captions.
YouTube Analyzer with AI — Transcript, Summary & Email
YouTube Video Analyzer with AI This workflow automatically extracts the transcript from any YouTube video, analyzes the content using an AI language model (DeepSeek), and sends a structured summary directly to your email. It is ideal for content creators, marketers, researchers, or anyone who needs to quickly digest video content without watching the full video. The workflow is triggered manually, making it perfect for on-demand analysis. You simply provide a YouTube URL, and the workflow handles everything from ID extraction to transcript fetching, AI summarization, and email delivery. Node-by-Node Breakdown When clicking ‘Test workflow’ (Manual Trigger — No auth) — This is the starting point. It allows you to run the workflow on demand by clicking the "Test workflow" button in the n8n editor. No scheduling or external trigger is required. Set YouTube URL (Set — No auth) — This node stores the YouTube video URL you want to analyze. You must manually edit the value (e.g., ) to point to your target video. It outputs the URL as a field called . YouTube Video ID (Code — No auth) — A JavaScript code node that extracts the 11-character video ID from the YouTube URL using a regex pattern. It supports both and URL formats. The extracted ID is passed to the next node as . Generate transcript (HTTP Request — Header Auth) — This node sends a POST request to the API to fetch the video transcript. It uses Header Auth (generic credential type) — you must provide an API key as a header. The request body contains the video ID in a JSON array. The response includes the transcript tracks. Get transcript (Set — No auth) — Extracts the transcript array and language from the API response. It maps to a field called and to . Exist? (IF — No auth) — A conditional node that checks if the array is not empty. If a transcript exists, the workflow continues to the analysis branch. If not, the workflow ends (no further nodes are connected for the false branch). Get Fulltext (Code — No auth) — A JavaScript node that concatenates all transcript text segments into a single string (). This prepares the full transcript for AI analysis. Analyze LLM Chain (LLM Chain — No auth) — The core AI analysis node. It uses the DeepSeek Chat Model (connected via ) and the Structured Output Parser (connected via ). The prompt instructs the AI to: - Generate a structured summary with sections like Definition/Background, Main Characteristics, Implementation Details, Advantages/Disadvantages - Use markdown formatting, bullet points, bold terms, and tables - Output a JSON object with and fields DeepSeek Chat Model (Language Model — API Key auth) — This node connects to DeepSeek's API using the model. You must configure a credential with your DeepSeek API key. Structured Output Parser (Output Parser — No auth) — Defines the expected JSON schema for the AI output. It expects an object with (string) and (string) properties. Send Email (Email Send — SMTP / OAuth2) — Sends the AI-generated summary via email. The subject is set to and the body to . You must configure an email credential (SMTP or OAuth2) in n8n. Sticky Notes — These are informational notes placed on the canvas to guide the user. They explain each step (e.g., "Get a FREE API on youtube-transcript.io and insert the Authentication", "Get the Youtube video ID from the URL"). Setup Instructions To use this workflow, you will need: n8n instance (self-hosted or cloud) YouTube Transcript API key — Sign up for a free API key at youtube-transcript.io. In n8n, create a Header Auth credential with the key as a header (e.g., ). DeepSeek API key — Create an account at platform.deepseek.com and generate an API key. In n8n, create a DeepSeek Chat Model credential. Email service credentials — Configure an SMTP or OAuth2 credential for sending emails (e.g., Gmail, Outlook, or any SMTP server). Once credentials are set, edit the Set YouTube URL node to replace with your target video URL, then click "Test workflow". Use Cases & Variations Content Research: Quickly summarize competitor videos or industry talks. Education: Generate study notes from lecture videos. Content Repurposing: Extract key points from videos to create blog posts or social media snippets. Multilingual Support: The workflow captures the transcript language — you could extend it to translate the summary using another AI model. Scheduled Monitoring: Replace the manual trigger with a Schedule Trigger to automatically analyze new videos from a playlist or channel RSS feed. Multiple AI Models: The workflow includes nodes for OpenAI and OpenRouter (disconnected) — you can easily switch to GPT-4o-mini or other models by connecting them to the LLM Chain. Save to Database: Instead of email, you could save the analysis to a Google Sheet, Airtable, or Notion database. Notes Not all YouTube videos have transcripts (especially live streams or very short videos). The workflow gracefully handles this with the Exist? conditional node. The free tier of youtube-transcript.io may have rate limits — check their pricing for higher usage.
Gmail to LINE: AI-Powered Email Summary & Forwarding
Overview This workflow automatically reads unread emails from your Gmail (or any IMAP-enabled email account), uses a free AI model to analyze and summarize important messages, and forwards the summaries directly to your LINE messaging app. It helps you stay on top of critical emails — like deadlines, payment reminders, meeting invites, and urgent requests — without having to constantly check your inbox. The workflow is especially useful for busy professionals, parents, or anyone who wants to avoid email overwhelm. By filtering out newsletters and promotions and only sending actionable summaries to LINE, it turns email triage into a fast, mobile-friendly experience. Node-by-Node Breakdown Read emails (IMAP) — Connects to your email server via IMAP to fetch unread emails. This node does not require authentication within n8n; instead, it uses the IMAP credentials (server, port, username, password) you configure in the node settings. It is set to take no further action on the emails after reading them. Basic LLM Chain — This is the AI processing core. It uses a prompt you define to analyze each email and determine if it is important (action items, deadlines, urgent requests, etc.) or not (newsletters, promotions). It outputs a structured result with an boolean and a string. OpenRouter Chat Model — Provides the AI model for the LLM Chain. It uses OpenRouter, which gives access to multiple LLMs. The configured model is (free tier). Authentication is done via Header Auth — you supply an API key as a Bearer token. Structured Output Parser — Ensures the AI response is in a consistent JSON format with (boolean) and (string) fields. This makes it easy to use the output in the next node. If — A conditional router that checks whether is . If important, the email summary is passed to the next node. If not, the workflow ends (no notification sent). Send summarized content to messenger — This HTTP Request node sends the summary to LINE's Messaging API. It uses Header Auth with . The POST request body includes the recipient LINE user ID and the summary text. Sticky Notes (4) — Informational notes that explain setup steps, credential configuration, and links to external resources (e.g., OpenRouter, LINE Developers console). Setup Instructions Email Account (IMAP): Enable IMAP access in your Gmail settings (or use any email provider that supports IMAP). You'll need your email address, IMAP server (e.g., ), port (usually 993), and an app password if you use 2FA. OpenRouter Account: Sign up for a free account at openrouter.ai. Generate an API key. In the node, create a new credential of type 'Header Auth' with: - Username: - Password: LINE Messaging API: Go to the LINE Developers Console, create a provider and a Messaging API channel. In the channel settings, issue a channel access token (long-lived). In the node, create a new 'Header Auth' credential with: - Username: - Password: LINE User ID: You need the recipient's LINE user ID. You can get this by having the user add your LINE bot as a friend and then using the endpoint or a webhook event to capture their ID. Replace in the node's JSON body with the actual user ID. Use Cases & Variations Daily Digest: Modify the workflow trigger to run on a schedule (e.g., every morning at 8 AM) instead of manually. Add an 'EmailReadIMAP' node that marks emails as read after processing to avoid duplicates. Slack or Discord: Replace the LINE HTTP Request node with Slack’s Webhook URL or Discord’s webhook endpoint to send summaries to those platforms instead. Multiple Recipients: Use a 'SplitInBatches' node or loop to send summaries to multiple LINE users or Slack channels. Custom AI Prompts: Adjust the 'Basic LLM Chain' prompt to categorize emails by urgency, department, or project. You can also ask the AI to extract specific data like invoice amounts or dates. Filter by Sender/Label: Add an 'IF' node before the LLM Chain to only process emails from certain senders or with specific keywords in the subject. Data Enrichment: Connect a 'Notion' or 'Google Sheets' node to log all summaries for later review or analytics.