CORTEXFLOW · FREE FOREVER

Automation

Gmail AI Auto-Labeling & Inbox Triage

↓ Download workflow JSON

Import in n8n: Workflows → ⋯ → Import from file, then add your credentials. Free download with a free account.

How it works

This template has two independent chains (the second one is not connected to the first — both run on their own triggers).

Chain 1 — instant triage:

  1. Gmail Trigger: New Email — fires on every new incoming message (polls every minute).
  2. OpenAI: Classify Email — reads the subject and snippet and classifies the email into exactly one category: urgent, action, fyi, or spam.
  3. Switch: Route by Category — sends the email down one of four branches based on the classification.
  4. Gmail: Apply Label (one node per branch) — applies the matching Gmail label (Urgent, Action, FYI, or Spam) to the message.

Chain 2 — daily digest:

  1. Schedule Trigger: Daily Digest — fires every day at 8:00 AM.
  2. Gmail: Fetch Labeled Unread — searches for unread emails labeled urgent or action from the last day.
  3. OpenAI: Summarize Digest — turns that list into a short plain-English digest with one line per email.
  4. Gmail: Send Digest — emails the digest to you.

Set up steps

You’ll need:

  • n8n (self-hosted or cloud)
  • An OpenAI account — get an API key at platform.openai.com → API keys
  • A Gmail account — connect via OAuth in n8n
  1. Download the workflow JSON using the download button on this page.
  2. In n8n, go to Workflows → ⋯ → Import from file and select the JSON.
  3. Create your OpenAI credential — in n8n go to Credentials → New → OpenAI, paste your API key, save. Then open both OpenAI nodes (OpenAI: Classify Email and OpenAI: Summarize Digest) and select your credential.
  4. Create your Gmail credential — in n8n go to Credentials → New → Gmail OAuth2, complete the OAuth flow, save. Open every Gmail node and select the credential.
  5. Create the labels in Gmail — go to Gmail → Settings → See all settings → Labels and create four labels: Urgent, Action, FYI, Spam. In n8n, open each Gmail: Apply Label node and set its labelIds to the matching label (for labels you create yourself, the label ID is usually the label name itself).
  6. Set your digest recipient — open Gmail: Send Digest and change the recipient to your own email address.
  7. Activate the workflow (toggle, top-right). New emails will be labeled within a minute, and the digest arrives at 8:00 AM daily.

Customize it

  • Change the categories — edit the prompt in OpenAI: Classify Email and rename the Switch branches and labels to match (e.g., receipts, newsletters).
  • Change the digest time — open Schedule Trigger: Daily Digest and edit the cron expression (0 8 * * * = 8:00 AM daily).
  • Skip spam from the digest — the digest query already only looks at urgent and action labels; adjust the q filter in Gmail: Fetch Labeled Unread to include or exclude categories.
  • Add an alert for urgent mail — connect a Slack or Telegram node after Gmail: Apply Label — Urgent to get pinged the moment something urgent arrives.

Workflow nodes

This workflow is built from 11 nodes. Here's what each one does:

#NodeTypeWhat it does
1 Gmail Trigger: New Email Gmail Trigger Starts the workflow when a new email arrives in Gmail.
2 OpenAI: Classify Email OpenAI Sends a prompt to OpenAI and returns the AI's answer.
3 Switch: Route by Category Switch Routes items to one of several outputs based on rules.
4 Gmail: Apply Label - Urgent Gmail Sends or reads email through your Gmail account.
5 Gmail: Apply Label - Action Gmail Sends or reads email through your Gmail account.
6 Gmail: Apply Label - FYI Gmail Sends or reads email through your Gmail account.
7 Gmail: Apply Label - Spam Gmail Sends or reads email through your Gmail account.
8 Schedule Trigger: Daily Digest Schedule Trigger Starts the workflow automatically on a schedule.
9 Gmail: Fetch Labeled Unread Gmail Sends or reads email through your Gmail account.
10 OpenAI: Summarize Digest OpenAI Sends a prompt to OpenAI and returns the AI's answer.
11 Gmail: Send Digest Gmail Sends or reads email through your Gmail account.

Setup instructions

1. Add your credentials

In n8n go to Credentials → New, create each credential below, then open the named node and select it:

NodeCredential to add
Gmail Trigger: New Email Gmail OAuth2
OpenAI: Classify Email OpenAI API
Gmail: Apply Label - Urgent Gmail OAuth2
Gmail: Apply Label - Action Gmail OAuth2
Gmail: Apply Label - FYI Gmail OAuth2
Gmail: Apply Label - Spam Gmail OAuth2
Gmail: Fetch Labeled Unread Gmail OAuth2
OpenAI: Summarize Digest OpenAI API
Gmail: Send Digest Gmail OAuth2

How this workflow starts

  • Gmail Trigger: Fires automatically on its event — activate the workflow and connect the service.
  • Schedule Trigger: Runs every cron.

Use cases

Your inbox is a to-do list written by other people, and reading all of it costs an hour a day. This template triages Gmail with AI in two independent chains. Chain 1 is instant: Gmail Trigger: New Email fires on every new message (polling each minute), OpenAI: Classify Email reads the subject and snippet and classifies it into exactly one category — urgent, action, fyi, or spam — and the Switch: Route by Category node sends it down one of four branches, each ending in a Gmail: Apply Label node that stamps the matching label. Chain 2 is the morning briefing: Schedule Trigger: Daily Digest fires at 8:00 AM, Gmail: Fetch Labeled Unread pulls unread urgent and action emails from the last day, OpenAI: Summarize Digest turns them into a short plain-English digest with one line per email, and Gmail: Send Digest emails it to you.

Founder getting 200 emails a day

A founder's inbox mixes investor updates, customer fires, newsletters, and noise — and the important email is always buried. With instant labeling, the Urgent label becomes the only inbox view that matters during the day: a customer outage email lands labeled Urgent within a minute of arrival, while newsletters quietly collect under FYI. The 8 AM digest means you start the day with a one-line-per-email summary of everything urgent or action-worthy from the last 24 hours instead of re-reading the inbox. Practical tip: add an alert node after Gmail: Apply Label — Urgent — a Slack or Telegram ping the moment something urgent arrives — so truly critical mail interrupts you even when you're not looking at email.

Customer support lead watching for escalations

A support lead needs to know about the angry enterprise customer before the ticket ages out. Tune the classification prompt in OpenAI: Classify Email so that escalation language, SLA keywords, and key-account domains count as urgent, and the label becomes an early-warning system: the support manager's Urgent view is a real-time escalation queue. The digest gives the Monday-morning picture of what the weekend left behind. Variation: rename the categories to match support workflows — edit the prompt and the Switch branches together (for example escalation, refund-request, feature-ask, noise) so labels map to your actual queue semantics.

Real estate investor juggling deals and contractors

An investor's email is deal flow, contractor quotes, property-manager updates, and spam in equal measure. The four default categories map well: deal emails with deadlines become urgent, quotes needing a decision become action, market newsletters become fyi, and the junk self-filters to spam. The daily digest replaces the evening inbox sweep — one email, one line per item, decisions queued for the morning. Because classification reads the subject and snippet, set up a filter habit: the AI can only classify what it sees, so keep subject lines meaningful in the mail you send (contractors will mirror them in replies). Tip: the digest query in Gmail: Fetch Labeled Unread already limits itself to urgent and action — adjust the q filter if you want FYI items included on weekends when you do deeper reading.

Freelancer separating money mail from noise

A freelancer's income depends on two email types: client work and invoices — everything else can wait. With triage running, the Action label collects the emails that need a reply or a deliverable, and the digest makes sure nothing urgent from a client slips past a busy week. Newsletters and cold pitches land in FYI or Spam without ever demanding attention. The customize path is easy: edit the prompt to add categories like receipts or prospect, rename the Switch branches and labels to match, and your bookkeeping mail self-organizes. Practical variation: change the digest time in Schedule Trigger: Daily Digest — a freelancer who works nights might prefer the digest at 10 PM as a next-day prep instead of 8 AM.

Agency owner with a team inbox to supervise

An agency owner doesn't read every client email — but needs to know when one is on fire. Point the workflow at the shared client-services inbox: urgent labels surface the "we're considering leaving" email within a minute, the digest gives the owner a daily one-line brief without opening the inbox, and the action label shows the account manager's real to-do list. The classification prompt can be tuned with client names and project codenames so the AI weighs context correctly. Tip: start with the four default labels for two weeks, then review what landed where — the misclassifications tell you exactly which phrases to add to the prompt, and one prompt edit improves every future email.

← All templates