Quick Overview
This workflow polls Gmail for new messages, uses OpenAI to classify each email into a category and priority with a short summary, and then applies matching Gmail labels (for example, AI/Urgent or AI/Sales Lead) when the labels exist in your account.
How it works
- Checks Gmail for new emails every minute.
- Normalizes each email (sender, subject, truncated body, message ID) and prepares it for classification.
- Sends the email content to OpenAI and receives a strict JSON result with category, priority, summary, whether a reply is needed, and a short reason.
- Validates and parses the OpenAI output, falling back to the “other” category if the response is invalid.
- Fetches all existing Gmail labels and maps each classified category (and optional priority) to a label ID using your configured prefix.
- Adds the resolved label(s) to the Gmail message when the target label exists, and skips emails where the expected label is missing.
Setup
- Add a Gmail OAuth2 credential and connect it to the Gmail Trigger and Gmail nodes.
- Add an OpenAI credential and connect it to the OpenAI classification node.
- Create the Gmail labels the workflow expects (for example, AI/Urgent, AI/Sales Lead, AI/Support, AI/Billing, AI/Newsletter-Spam, and AI/Other) or update the label prefix and mappings to match your labels.
- Update the Settings values (business name, OpenAI model, optional classification notes, and maximum body length) and optionally enable priority labels if you also create AI/Priority-High, AI/Priority-Medium, and AI/Priority-Low.