This workflow corresponds to n8n.io template #4507 — we link there as the canonical source.
This workflow follows the Agent → Gmail recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "IYMbUalwaX81VJs4",
"meta": {
"templateCredsSetupCompleted": true
},
"name": "Auto Spam/Marketing & Offer Delete",
"tags": [],
"nodes": [
{
"id": "d3c54552-91c2-4b7f-b9ce-f6cf2a28d615",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-80,
60
],
"parameters": {
"filters": {},
"pollTimes": {
"item": [
{
"mode": "everyHour"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "322d373c-84c9-4b2a-a68a-fc977788f973",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
140,
260
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-nano",
"cachedResultName": "gpt-4.1-nano"
},
"options": {}
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "39ace162-640d-4350-9d43-142d335752be",
"name": "If",
"type": "n8n-nodes-base.if",
"position": [
520,
60
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "or",
"conditions": [
{
"id": "3fa478cd-9476-4a10-b039-1e537b838b31",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output }}",
"rightValue": "SPAM"
},
{
"id": "82bafdff-daed-4791-8dd0-dae981c0ee43",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output }}",
"rightValue": "OFFER"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "89d0576e-1523-4684-9c7c-8af12464a648",
"name": "Validator of Email",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
160,
60
],
"parameters": {
"text": "=Tu masz ostatni\u0105 wiadomo\u015b\u0107 email: \n {{ $json.snippet }}",
"options": {
"systemMessage": "=You are an intelligent assistant for analyzing and classifying emails or contact form messages.\n\nYour task is to accurately assess whether the message contains **valuable information** or is a **standard commercial message with no real value to the recipient**.\n\nWe distinguish three classes:\n\n1. `SPAM` \u2013 bulk messages, low-quality content, random text, scam, phishing, etc. \n2. `OFFER` \u2013 commercial or marketing messages that promote something but **do not contain information important to the user**, e.g.:\n - Discount coupons \n - Promotion or sale announcements \n - Abandoned cart reminders \n - Invitations to register, download, or purchase \n - Cold emails and collaboration offers \n3. `IMPORTAND` \u2013 messages containing **important information for the recipient**, even if commercial in nature, e.g.:\n - Order or payment confirmation \n - Shipping or delivery status \n - Message from a specific person with a question or request \n - Private matters, invitations, inquiries \n\nRules:\n- If in doubt, mark as `IMPORTAND`.\n- Focus on the message content, do not evaluate email address or headers.\n- Respond with only **one word**: `SPAM`, `OFFER`, or `IMPORTAND`.\n\nExamples:\n\nMessage: \n\"Your order #14235 has been shipped. Expected delivery: Thursday.\" \nResponse: `IMPORTAND` \n\ud83d\udccc This is important information for the user \u2013 do not delete.\n\n---\n\nMessage: \n\"You left something in your cart! Today only -15% off your purchase!\" \nResponse: `OFFER` \n\ud83d\udccc Typical marketing reminder, no concrete value.\n\n---\n\nMessage: \n\"Hi, we noticed you haven\u2019t downloaded our free e-book. Download now and learn 10 ways to increase sales.\" \nResponse: `OFFER` \n\ud83d\udccc Marketing pitch, lacks important content.\n\n---\n\nMessage: \n\"Attached is the invoice for the service completed last month. Contact me if you have any questions.\" \nResponse: `IMPORTAND` \n\ud83d\udccc Invoice = important message.\n\n---\n\nMessage: \n\"Only today! Free shipping and up to -30% discounts in our store!\" \nResponse: `OFFER` \n\ud83d\udccc Promotion, typical commercial info.\n\n---\n\nMessage: \n\"Hi, I saw your ad online and I\u2019m interested in collaborating. Can we talk by phone?\" \nResponse: `IMPORTAND` \n\ud83d\udccc Message from a specific person = potential lead.\n\n---\n\nMessage: \n\"Win a new iPhone! Click here and claim your prize!\" \nResponse: `SPAM` \n\ud83d\udccc No explanation needed \u2013 scam/spam.\n\n---\n\nMessage: \n\"I\u2019d like to ask if you offer individual training?\" \nResponse: `IMPORTAND` \n\ud83d\udccc Genuine message from an interested customer.\n\n---\n\nMessage: \n\"Register now to get free access to XYZ tool for 7 days.\" \nResponse: `OFFER` \n\ud83d\udccc Promotional offer, not inherently important.\n"
},
"promptType": "define"
},
"typeVersion": 1.9
},
{
"id": "30698570-1181-4164-8d19-3e944fcae486",
"name": "Delate Email",
"type": "n8n-nodes-base.gmail",
"position": [
780,
60
],
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "delete"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "c1476511-b49b-410e-9665-47d04f26c92a",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
1040,
-260
],
"parameters": {
"width": 660,
"height": 1060,
"content": "### \ud83d\udccc Workflow: Auto Spam/Marketing Offer Killer Copy\n\n**Description** \nThis workflow automatically monitors your Gmail inbox and **classifies incoming emails** into one of three categories:\n\n- `SPAM`: Low-value, scam, or irrelevant bulk messages \n- `OFFER`: Standard marketing/commercial offers without user-relevant information \n- `IMPORTAND`: Important and valuable messages, even if commercial (e.g. invoices, personal inquiries)\n\nIf a message is classified as `SPAM` or `OFFER`, it is **automatically deleted** from your Gmail inbox.\n\n---\n\n### \u2699\ufe0f Components Used\n\n- **Gmail Trigger** \u2013 Checks for new messages every hour \n- **Validator of Email (OpenAI)** \u2013 Uses GPT-based logic to analyze and classify the message \n- **IF Node** \u2013 Filters for SPAM and OFERTA categories \n- **Gmail Delete** \u2013 Deletes irrelevant messages automatically\n\n---\n\n### \u26a0\ufe0f Warnings & Information\n\n- **Permanent deletion**: Emails marked as SPAM or OFFER are deleted without confirmation. Use with caution.\n- **No human review**: The system relies entirely on AI classification. False positives may occur.\n- **Language-specific**: The AI prompt is in English.\n- **Inactive by default**: You need to manually activate the workflow in n8n.\n- **Testing recommended**: Always test on a non-critical Gmail account before full deployment.\n\n---\n\n### \u2705 Use Case\n\nIdeal for:\n- Freelancers tired of cold emails \n- Business owners who want a clean inbox \n- Anyone filtering out marketing and spam noise while keeping valuable emails untouched\n"
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "988b967f-e77d-4698-af25-93c44b601aec",
"connections": {
"If": {
"main": [
[
{
"node": "Delate Email",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Validator of Email",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Validator of Email",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Validator of Email": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
gmailOAuth2openAiApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This workflow is designed for freelancers, solopreneurs, and business owners who receive a high volume of irrelevant messages in their Gmail inbox — from cold offers to spammy promotions — and want to automatically filter and delete them using AI. Its main purpose is to scan new…
Source: https://n8n.io/workflows/4507/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Since Gmail inboxes can quickly become cluttered, this workflow provides an automated AI-based email classification system. It listens for new emails, categorizes them using an AI classifier, applies
This guide walks you step by step through setting up an automated agent that: Receives emails sent by your customers. Analyzes the content of the email. Generates an appropriate response using an AI m
Welcome to your hands-on guide for building a resilient, intelligent email support system in n8n! This workflow is specifically designed as an educational tool to help you understand advanced AI autom
Gmail Googlecalendartool. Uses stickyNote, lmChatOpenAi, gmail, gmailTrigger. Event-driven trigger; 10 nodes.
The purpose of this n8n workflow is to automate the process of identifying incoming Gmail emails that are requesting an appointment, evaluating their content, checking calendar availability, and then