AutomationFlowsEmail & Gmail › Auto-clean Gmail Spam Folder - Monthly Using Gmail API

Auto-clean Gmail Spam Folder - Monthly Using Gmail API

ByOneclick AI Squad @oneclick-ai on n8n.io

This automated n8n workflow uses the Gmail API to clean the spam folder by permanently deleting all emails on the first day of each month. The system ensures efficient email management and improves Gmail storage by removing unwanted spam emails. Gmail API rate limits should be…

Cron / scheduled trigger★★★☆☆ complexity8 nodesGmail
Email & Gmail Trigger: Cron / scheduled Nodes: 8 Complexity: ★★★☆☆ Added:

This workflow corresponds to n8n.io template #6122 — we link there as the canonical source.

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
{
  "id": "hdBpjh9528K5FyWV",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Auto-Clean Gmail Spam Folder Monthly with Gmail API",
  "tags": [],
  "nodes": [
    {
      "id": "e214c477-6d39-426f-8a34-cd38bb6f5ae2",
      "name": "Monthly Trigger (1st Day)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -380,
        120
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "months",
              "triggerAtHour": 6
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e8eb600c-9b45-44e2-8ee6-409c9b61b171",
      "name": "Fetch SPAM Emails (Gmail)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -160,
        120
      ],
      "parameters": {
        "filters": {
          "labelIds": [
            "SPAM"
          ]
        },
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "96a0fd3c-63bd-48f4-87d7-7eda528b50a3",
      "name": "Pause Before Deletion (5s)",
      "type": "n8n-nodes-base.wait",
      "position": [
        60,
        120
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "e172bbb8-069c-4c68-b72f-cf2a7f304f0b",
      "name": "Delete Fetched SPAM Emails",
      "type": "n8n-nodes-base.gmail",
      "position": [
        280,
        120
      ],
      "parameters": {
        "messageId": "={{ $json.id }}",
        "operation": "delete"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "a07dd87f-1216-44de-91b8-a6d7d36877e8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -415,
        -80
      ],
      "parameters": {
        "color": 3,
        "width": 170,
        "height": 360,
        "content": "Starts the workflow automatically on the 1st of every month to perform email cleanup."
      },
      "typeVersion": 1
    },
    {
      "id": "0de7be15-2ebe-4c28-ab52-59f35f6a3135",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -200,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 170,
        "height": 360,
        "content": "Uses Gmail API to retrieve all emails in the SPAM folder for the authenticated Gmail account."
      },
      "typeVersion": 1
    },
    {
      "id": "11c0f2f1-1480-4512-ad4d-1d9544838e2c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -80
      ],
      "parameters": {
        "width": 170,
        "height": 360,
        "content": "Introduces a short delay to avoid hitting Gmail\u2019s API rate limits or ensure all emails are fetched properly."
      },
      "typeVersion": 1
    },
    {
      "id": "0600f919-8315-431a-8420-9c0931b9c097",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -80
      ],
      "parameters": {
        "color": 4,
        "width": 170,
        "height": 360,
        "content": "Permanently deletes all emails retrieved from the SPAM folder to free up Gmail space and improve email hygiene."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ad4a18bb-1aff-4520-9e68-4844bf365d8f",
  "connections": {
    "Fetch SPAM Emails (Gmail)": {
      "main": [
        [
          {
            "node": "Pause Before Deletion (5s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Monthly Trigger (1st Day)": {
      "main": [
        [
          {
            "node": "Fetch SPAM Emails (Gmail)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pause Before Deletion (5s)": {
      "main": [
        [
          {
            "node": "Delete Fetched SPAM Emails",
            "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.

Pro

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

About this workflow

This automated n8n workflow uses the Gmail API to clean the spam folder by permanently deleting all emails on the first day of each month. The system ensures efficient email management and improves Gmail storage by removing unwanted spam emails. Gmail API rate limits should be…

Source: https://n8n.io/workflows/6122/ — 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 automates the backup of all your n8n workflows to a specified Google Drive folder. It operates in two main phases: Orchestration (Scheduled Task): The workflow is initiated by a Schedule

n8n, Google Drive, Execution Data +3
Email & Gmail

This n8n template allows you to automatically monitor your company's budget by comparing live Bexio accounting data against targets defined in Google Sheets, sending automated weekly email reports. It

Google Sheets, HTTP Request, Gmail
Email & Gmail

Klaviyo List Decay Detection

HTTP Request, Postgres, Error Trigger +1
Email & Gmail

This workflow automatically generates and emails a comprehensive security audit report for your N8N instance every week. It identifies potential security risks related to: Credentials 🔑 : Exposed or i

Gmail, n8n
Email & Gmail

Automatically identify clients who haven’t been contacted in 14+ days and re-engage them with personalized Gmail follow-up emails, Google Sheets tracking, and Slack notifications for account managers.

High Level, Gmail, Google Sheets +2