AutomationFlowsEmail & Gmail › Automated Gmail Spam Cleanup Workflow

Automated Gmail Spam Cleanup Workflow

Original n8n title: Clean My Mail

Clean My Mail. Uses gmail. Scheduled trigger; 12 nodes.

Cron / scheduled trigger★★★★☆ complexity12 nodesGmail
Email & Gmail Trigger: Cron / scheduled Nodes: 12 Complexity: ★★★★☆ Added:

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 →

Download .json
{
  "name": "Clean My Mail",
  "nodes": [
    {
      "parameters": {
        "operation": "delete",
        "messageId": "={{ $json.id }}"
      },
      "name": "Delete All Mails",
      "type": "n8n-nodes-base.gmail",
      "position": [
        320,
        500
      ],
      "typeVersion": 2.1,
      "id": "8a921410-15a0-4b0e-9104-19ffa1dd51d0",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## \ud83d\udce7 Gmail Setup\n1. Make sure all Gmail nodes use valid and connected Gmail OAuth2 credentials.\n2. To delete different email categories, adjust the labels in each Gmail node:\n   - 'Get all SPAM emails' \u2192 label: SPAM\n   - 'Get all Social' \u2192 label: CATEGORY_SOCIAL\n   - 'Get all Promotions' \u2192 label: CATEGORY_PROMOTIONS\n",
        "height": 740,
        "width": 500
      },
      "name": "Adjustments",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -740,
        120
      ],
      "typeVersion": 1,
      "id": "0b0fe192-6ead-4011-b469-79da8f8033ff"
    },
    {
      "parameters": {
        "content": "## \u23f0 Scheduled Trigger\n- This workflow runs automatically every 3 days.\n- You can change the interval in the \"Trigger Every Three Days\" node to suit your needs.\n",
        "height": 240,
        "width": 360
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1220,
        360
      ],
      "id": "b4e2ca40-3850-478f-b78d-b6814353a68a",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## \ud83d\udd00 Merge & Prepare IDs\n- The \"Merge\" node combines results from all three Gmail nodes (SPAM, Social, Promotions).\n- \"Split Out\" node splits the list so each email ID can be processed individually.\n",
        "height": 240,
        "width": 420
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -180,
        360
      ],
      "id": "25bb2611-3188-478b-ac6d-23ed621b4d50",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## \ud83d\uddd1\ufe0f Delete Emails\n- The \"Delete All Mails\" node deletes emails using their message IDs.\n- Double-check the labels in earlier steps to avoid accidentally deleting important emails.\n",
        "height": 240,
        "width": 420
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        300,
        360
      ],
      "id": "1393ff41-bafd-437c-877f-be9e62c109c0",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "daysInterval": 3
            }
          ]
        }
      },
      "name": "Run Every 3 Days (Trigger)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -960,
        500
      ],
      "typeVersion": 1.2,
      "id": "cbbbaf18-29e4-4a97-8614-3dfeeced42a7"
    },
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": true,
        "filters": {
          "labelIds": [
            "SPAM"
          ]
        }
      },
      "name": "Fetch SPAM Emails",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -540,
        320
      ],
      "typeVersion": 2.1,
      "alwaysOutputData": true,
      "id": "ecc3647d-f81c-4605-8f66-2a47d20b7dde",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": true,
        "filters": {
          "labelIds": [
            "CATEGORY_SOCIAL"
          ]
        }
      },
      "name": "Fetch Social Emails",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -540,
        500
      ],
      "typeVersion": 2.1,
      "alwaysOutputData": true,
      "id": "4a288d12-0fb4-44aa-9c41-242cae4f5dd6",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": true,
        "filters": {
          "labelIds": [
            "CATEGORY_PROMOTIONS"
          ]
        }
      },
      "name": "Fetch Promotion Emails",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -540,
        680
      ],
      "typeVersion": 2.1,
      "alwaysOutputData": true,
      "id": "f65f55af-3374-42fd-98fe-2cfd543077a5",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.1,
      "position": [
        -160,
        500
      ],
      "id": "5b1f0245-960c-4c38-a3c9-8545f7838836",
      "name": "Combine All Fetched Emails"
    },
    {
      "parameters": {
        "fieldToSplitOut": "id",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        40,
        500
      ],
      "id": "f97101f1-592e-4295-b3f1-a632a5a15551",
      "name": "Split Email IDs (One per item)"
    },
    {
      "parameters": {
        "content": "## \u2615 Hey, this tool is totally free!\n\nIf you have any suggestions, feedback, or just wanna say hi \u2014 feel free to[reach out](https://khmuhtadin.com).\n\nWanna support my caffeine needs? [Buy me a coffee](https://buymeacoffee.com/khmuhtadin) \u2615\u2764\ufe0f\n\nThanks & happy automating!\n",
        "height": 240,
        "width": 420,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -180,
        700
      ],
      "id": "8d354e0a-0d21-4446-8b58-3d86eb5fbc8d",
      "name": "Sticky Note3"
    }
  ],
  "connections": {
    "Delete All Mails": {
      "main": [
        []
      ]
    },
    "Run Every 3 Days (Trigger)": {
      "main": [
        [
          {
            "node": "Fetch SPAM Emails",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Social Emails",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Promotion Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch SPAM Emails": {
      "main": [
        [
          {
            "node": "Combine All Fetched Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Social Emails": {
      "main": [
        [
          {
            "node": "Combine All Fetched Emails",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Fetch Promotion Emails": {
      "main": [
        [
          {
            "node": "Combine All Fetched Emails",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Combine All Fetched Emails": {
      "main": [
        [
          {
            "node": "Split Email IDs (One per item)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Email IDs (One per item)": {
      "main": [
        [
          {
            "node": "Delete All Mails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "34278343-eec2-4602-90f8-60d4cfa3bc3f",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "dI8MDIAVRPRIMA9K",
  "tags": []
}

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.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow automates the routine chore of clearing out your Gmail inbox, saving you hours of manual sorting and deletion each week. It targets spam and social media emails that clutter your primary folders, ensuring a tidier, more focused email experience for busy professionals or anyone overwhelmed by digital noise. The key step involves a scheduled trigger that runs every three days to fetch and delete these unwanted messages via Gmail integration, with optional adjustments for custom rules.

Use this workflow if you receive high volumes of promotional or spam emails and want a set-it-and-forget-it solution to maintain inbox hygiene without daily intervention. Avoid it for users needing granular control over deletions, such as preserving certain newsletters, or those with low email traffic where automation feels unnecessary. Common variations include tweaking the schedule to daily runs or expanding to archive rather than delete specific categories like newsletters.

About this workflow

Clean My Mail. Uses gmail. Scheduled trigger; 12 nodes.

Source: https://github.com/khmuhtadin/n8n-template/blob/main/Gmail/Clean-SPAM-Promotions-Social-from-gmail.json — original creator credit. Request a take-down →

More Email & Gmail workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Email & Gmail

This workflow runs daily at 9 AM to pull unpaid invoices from Microsoft SQL, send staged payment reminder emails via Gmail based on due date timing, update invoice status and an audit log in the datab

Microsoft Sql, Gmail
Email & Gmail

Relatórios aos Laboratórios. Uses httpRequest, gmail, formTrigger. Scheduled trigger; 54 nodes.

HTTP Request, Gmail, Form Trigger
Email & Gmail

YOUR_ID 4. Uses gmail, googleDrive, googleSheets, httpRequest. Scheduled trigger; 53 nodes.

Gmail, Google Drive, Google Sheets +1
Email & Gmail

14310 Send Overdue Invoice Payment Reminders With Ifirma Gmail Postgrid And Slack. Uses httpRequest, stopAndError, slack, gmail. Scheduled trigger; 53 nodes.

HTTP Request, Stop And Error, Slack +1
Email & Gmail

Addendo — Blog Automatico Don Jacinto Nahual. Uses httpRequest, redis, github, gmail. Scheduled trigger; 51 nodes.

HTTP Request, Redis, GitHub +1