Auto-Tag Emails with n8n: Full Workflow, JSON, and Setup Guide


1. Introduction
Problem:
Manually organizing emails is time-consuming.
Solution:
Using n8n, we can auto-tag emails based on keywords or AI analysis. This helps with faster processing, prioritization, and better data management.
Use cases:
- Prioritize client support tickets
- Route sales leads to the right team
- Organize newsletters, promotions, and personal mails automatically
2. How it Works
Workflow overview:
New Email arrives → Analyze content → Identify keyword → Assign tag → Update email
You can set up:
- Static keyword detection (if email includes “invoice” → tag = “Finance”)
- AI-powered detection (optional: using OpenAI or Hugging Face for classification)
3. Required Tools
- Email node (IMAP or Gmail integration)
- IF node (to check for keywords)
- Set node (to assign tags)
- Optional: NLP service (like OpenAI) for intelligent tagging
- Gmail/IMAP node (to modify or label emails)
4. Step-by-Step Setup
Step 1: Trigger — Get New Email
- Node: Email Trigger (IMAP/POP3 or Gmail trigger)
Settings:
- Monitor inbox
- Check for unread emails
Step 2: Analyze Email Content
- Node: IF node
- Condition: Check if email body/subject contains certain words
Example:
- If subject includes “invoice” ➔ Tag = Finance
- If subject includes “job application” ➔ Tag = HR
- If body mentions “urgent” ➔ Tag = Priority
Step 3: Set Tag
- Node: Set node
- Create a new field
tag
and set the value based on the matched condition.
Step 4: Apply Label
- Node: Gmail node (modify email) OR update a database record
- Apply the label or save the result.
Optional (Advanced):
Use OpenAI Node to automatically classify content using AI.
Prompt Example:
Classify this email into one of the categories: [Finance, HR, Support, Marketing, Personal].
JSON Code for n8n
Here’s a basic auto-tagging flow you can import into n8n directly:
{
"nodes": [
{
"parameters": {
"format": "resolved",
"options": {}
},
"id": "EmailTrigger",
"name": "IMAP Email Trigger",
"type": "n8n-nodes-base.emailReadImap",
"typeVersion": 1,
"position": [250, 300]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json[\"subject\"]}}",
"operation": "contains",
"value2": "invoice"
}
]
}
},
"id": "IF_Invoice",
"name": "Check for Invoice",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [500, 300]
},
{
"parameters": {
"values": {
"string": [
{
"name": "tag",
"value": "Finance"
}
]
}
},
"id": "Set_Tag_Invoice",
"name": "Set Finance Tag",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [750, 200]
},
{
"parameters": {
"values": {
"string": [
{
"name": "tag",
"value": "General"
}
]
}
},
"id": "Set_Tag_General",
"name": "Set General Tag",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [750, 400]
}
],
"connections": {
"IMAP Email Trigger": {
"main": [
[
{
"node": "Check for Invoice",
"type": "main",
"index": 0
}
]
]
},
"Check for Invoice": {
"main": [
[
{
"node": "Set Finance Tag",
"type": "main",
"index": 0
},
{
"node": "Set General Tag",
"type": "main",
"index": 1
}
]
]
}
}
}
This checks if the email subject contains “invoice”. If yes, it tags it as “Finance”; otherwise, “General.”
Find us
Balian’s Blogs Balian’s
linkedin Shant Khayalian
Facebook Balian’s
X-platform Balian’s
web Balian’s
Youtube Balian’s
#n8n #Automation #EmailAutomation #WorkflowAutomation #ProcessOptimization #InboxZero #ProductivityTools #AIIntegration #BusinessAutomation #NoCodeTools