Skip to content
NEWMarketplace and the trig8n Agent: sell what you build, and get plans and changes that are tested before you see them. See what is new

Library / Email Automation

Email Automation

Classify and label new Gmail emails with OpenAI GPT-4.1 mini

Checks Gmail every minute for new messages, classifies each with OpenAI by category and priority, and applies the matching Gmail label with a one-line summary.

What it does

# Classify and label new Gmail emails with OpenAI ## Who is this for Small business owners, freelancers and support teams whose Gmail inbox mixes customer requests, sales leads, invoices and newsletters. ## How it works 1. Gmail Trigger checks for new emails every minute. 2. Settings holds your business name, model and optional sorting rules. 3. OpenAI classifies each email as Urgent, Sales Lead, Support, Billing, Newsletter/Spam or Other, with a high/medium/low priority and a one-line summary (strict JSON schema). 4. The workflow looks up your Gmail labels and adds the matching one, e.g. AI/Sales Lead. Anything the AI can't classify is filed as Other. ## How to set up 1. Attach your Gmail OAuth2 credential to the Gmail nodes and your OpenAI credential to *Classify Email*. 2. In Gmail, create the labels AI/Urgent, AI/Sales Lead, AI/Support, AI/Billing, AI/Newsletter-Spam, AI/Other. 3. Open Settings: set business_name, openai_model (default gpt-4.1-mini) and optional classification_notes, e.g. "emails from @bigclient.com are urgent". 4. Send yourself a test email, click Execute workflow, check the label, then activate. ## Requirements - n8n (Cloud or self-hosted) - Gmail account - OpenAI API key (usage billed by OpenAI) ## How to customize - Change category definitions in the *Classify Email* system prompt. - Rename labels in the NAMES map in *Resolve Labels*. - Turn on add_priority_labels to also add AI/Priority-High/Medium/Low. - Swap the OpenAI node for another provider's chat model with an LLM Chain.

The steps

  1. Gmail Trigger
  2. Settings
  3. Prepare Email
  4. Classify Email
  5. Parse Classification
  6. Get Gmail Labels
  7. Resolve Labels
  8. Has Label?
  9. Apply Gmail Label

Similar automations