n8n workflow template · 9 nodes · Gmail
Basic Automatic Gmail Email Labelling with OpenAI and Gmail API is a free n8n workflow template that starts from the Gmail Trigger node and works with Gmail and OpenAI. It has 9 nodes, 3 of them AI nodes (OpenAI Chat Model, AI Agent and Window Buffer Memory). The notes inside the workflow say: “Poll Gmail every x minutes, trigger when a new email is received.” To run it, you add your own credentials for Gmail OAuth2 and OpenAI API.
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Poll Gmail every x minutes, trigger when a new email is received.
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Objective: Automatically categorize incoming emails based on existing Gmail labels or create a new label if none match.
Analyze the email's subject, sender, recipient, keywords, and content. Compare with existing Gmail labels to find the most relevant match. Label Assignment
Assign the email to the most appropriate existing label. Remove the inbox label if the email is of less importance (like ads, promotions, aka "Reclame"), keep normal and important emails in the inbox. If no suitable label exists, create a new label based on the existing labels. Try reusing existing labels as much as possible. Always create a label as a sublabel, if no label applies, if the main label already exists, create the new label under the existing label, if no main label exists, create the label AI and create the new label under this label. Label Creation
Ensure new labels align with the structure of existing ones, including capitalization, delimiters, and prefixes. Examples
If the email subject is "Project Alpha Update," assign to [Project Alpha] if it exists. For "New Vendor Inquiry," create "Vendor Inquiry" if no relevant label exists. Outcome: Emails are consistently categorized under the appropriate or newly created labels, maintaining Gmail's organizational structure.
The 9 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:
Configure your own credentials after importing. Create each credential in n8n, then select it in the node.
Do you need somewhere to run it? Read our guide to self-hosted n8n.
We can adapt this workflow to your apps, data and process, then deploy and support it.
Contact Us