Quick overview
Watches Gmail for new unread mail, then an AI agent on Google Gemini sorts each one into a category — including a phishing/fraud check — and applies the matching Gmail label itself. Every result gets logged to Google Sheets with sender, subject, category, and timestamp.
How it works
- Checks Gmail every minute for new unread emails.
- Retrieves all labels from the connected Gmail account and matches the five category label names to their Gmail label IDs.
- Sends each email’s subject, sender, and preview text to a Google Gemini-powered AI agent to choose exactly one category (Possible Fraud, Urgent, Ads, Review, or Not Important).
- Applies the selected category as a Gmail label to the original email using the matching label ID.
- Combines the email details with the AI’s selected category and appends a row to Google Sheets with the classification result and timestamp.
Setup
- Create five Gmail labels with these exact names: ⚠️ Possible Fraud, 🔴 Urgent, 📢 Ads, 🔎 Review, ⚪ Not Important.
- Connect your Gmail account credentials so the workflow can watch the inbox, list labels, and apply labels.
- Connect Google Gemini (Google AI) credentials for the chat model used by the AI agent.
- Connect Google Sheets credentials and set the target spreadsheet ID and sheet/tab name in “Set log sheet details”.
- Ensure the Google Sheet has columns (or headers) for subject, from, category, and classified_at so appended rows match your logging format.
Requirements
- A Gmail account (OAuth2)
- A Google Sheet for logging (OAuth2)
- A Google Gemini API key (Google AI Studio — free tier available)
Customization
- Tighten or loosen the fraud-detection criteria in the agent's system prompt, or add a dedicated alert email that fires only for Possible Fraud.
- Add, rename, or merge the non-security categories by updating the prompt and adding a matching Gmail label plus tool node.
- Swap the Sheet log for n8n's Data Table, or adjust the polling interval and unread-only filter.