Automate Gmail Email Classification with Google Gemini & n8n

This workflow solves the problem of manually sorting emails by automatically classifying and labeling incoming Gmail messages using Google Gemini chat model in n8n. It boosts inbox organization and saves time while reducing missed high priority emails.
gmailTrigger
lmChatGoogleGemini
textClassifier
+4
Workflow Identifier: 2218
NODES in Use: gmailTrigger, lmChatGoogleGemini, textClassifier, gmail, agent, lmChatGroq, stickyNote

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

What This Workflow Does

This workflow watches your Gmail inbox. When a new email arrives, it reads the email text. Then, it decides if the email is High Priority, related to school work, a Promotion, or Other. After deciding, it adds a matching Gmail label to help organize your emails fast and clearly.

This saves you hours of sorting and helps you see important emails fast. It uses Google Gemini AI to understand email content and sort correctly. Labels make your inbox neat and easy to manage.


Who Should Use This Workflow

This is good for anyone getting lots of emails every day, like administrators or office workers at schools. It helps if emails come from many senders about urgent work or promotions. It works well where you want to quickly find important, work, or promotional emails without searching.


Tools and Services Used

  • Gmail Trigger Node: Detects new emails in your mailbox.
  • Google Gemini Chat Model Node: Classifies email content using AI.
  • Classification Agent Node: Uses a clear prompt to assign emails to categories.
  • Gmail Label Nodes: Add labels like “High Priority” or “Promotion” to emails.
  • Optional AI Agent Node: Can send smart replies when enabled.
  • n8n: Automation platform to run the workflow.

You can use self-host n8n to manage n8n on your own server for better control.


Beginner Step-by-Step: How to Use This Workflow in n8n

Step 1: Import the Workflow

  1. Download the workflow file using the Download button on this page.
  2. Open n8n editor and click on “Import from File.”
  3. Select the downloaded workflow file to import it.

Step 2: Add Credentials

  1. Add your Gmail OAuth2 credentials in n8n Credential Manager.
  2. Also add your Google PaLM API Key to use Google Gemini.

Step 3: Update Labels and IDs

  1. Check the Gmail Label nodes. Update Gmail label IDs if necessary.
  2. Make sure labels like “High Priority,” “Kajonkietsuksa School,” and “Promotion” exist in your Gmail inbox.

Step 4: Test the Workflow

  1. Send test emails matching the categories to your Gmail.
  2. Observe if the workflow adds correct labels automatically.

Step 5: Activate for Production

  1. Turn on the toggle button to activate the workflow.
  2. Monitor the workflow as new emails arrive.

Inputs, Processing Steps, and Outputs

Inputs

  • New emails arriving in the Gmail inbox.

Processing Steps

  • Gmail Trigger: Watches for emails every minute.
  • Google Gemini Chat Model: Reads email text and decides category.
  • Classification Agent: Uses preset keywords and categories to classify email.
  • Gmail Label Nodes: Add labels based on category for organization.
  • Optional AI Agent: Can create smart replies but is off by default.

Outputs

  • Emails labeled with one of: High Priority, KS Work Related, Promotion, or Other.
  • Organized inbox where important emails stand out.
  • Optionally, automatic replies if enabled.

Customizations

  • Add More Categories:
    Add new category names in Classification Agent prompt. Add corresponding Gmail label nodes.
  • Adjust Keywords:
    Change keywords for each category in system prompt inside Classification Agent.
  • Set Polling Interval:
    Change Gmail Trigger polling from 1 to 5 minutes if preferred.
  • Enable Auto Replies:
    Activate AI Agent node and connect Gmail send node to reply automatically.

Troubleshooting

  • Gmail Trigger Not Detecting Emails:
    Check OAuth2 credentials are valid and refreshed.
  • Emails Not Labeled Correctly:
    Confirm Gmail label IDs match your Gmail labels.
  • Unclear Classification Output:
    Refine category descriptions and keyword hints in Classification Agent prompt.

Pre-Production Checklist

  • Confirm Gmail OAuth2 credentials have label read/write permissions.
  • Verify Google Gemini API key is active and has quota.
  • Create Gmail labels before running workflow.
  • Test workflow using sample emails to verify results.
  • Backup Gmail label setup if necessary.

Deployment Guide

Activate the workflow toggle in n8n to start automation.

Watch workflow executions for errors or misses.

Adjust polling frequency to match email volume.

Add notifications for failures if workflow scope increases.


Summary of Benefits

✓ Saves over 2 hours per day on email sorting.

✓ Automatically adds clear labels to incoming emails.

✓ Helps you see important and school-related emails quickly.

✓ Ready for smart auto-replies if enabled.

✓ Easy to customize categories and keywords.


System prompt example for Classification Agent:

"Classify emails into one of four categories: High Priority, KS Work Related, Promotion, or Other.
Use keywords to help decide category:
- High Priority: urgent, immediate, action needed
- KS Work Related: school, teacher, student, meeting, class
- Promotion: sale, discount, offer, deal
- Other: all others

Reply with only the category name."

Frequently Asked Questions

Check the Gmail OAuth2 credentials in n8n. Reauthenticate if expired or incorrect.
Make sure Gmail label IDs in the label nodes match your actual Gmail labels exactly.
Yes, replace the Google Gemini Chat Model node with supported LLM nodes like the Groq Chat Model and update credentials.
Yes, activate the AI Agent node and connect it to a Gmail send node to enable auto replies.

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free