Monthly Gmail Spam Folder Auto-Cleaner - n8n Workflow

Use this robust n8n workflow to automate the monthly cleanup of your Gmail Spam folder. This n8n template uses the Schedule n8n trigger and Gmail n8n node for guaranteed mailbox hygiene and storage savings.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Individuals or businesses looking to automate routine email maintenance.
Users who frequently hit Gmail storage limits due to accumulated spam.
Automation specialists seeking reliable, scheduled n8n templates for email hygiene.
Anyone interested in leveraging the Schedule n8n trigger for routine tasks.

Overview

Keeping a clean inbox often involves manually clearing out the spam folder, a task that is easily forgotten and can lead to unnecessary consumption of storage space. This automated solution solves that problem by providing a 'set-it-and-forget-it' mechanism. This specialized n8n workflow leverages the powerful Schedule n8n trigger to run reliably every month. It utilizes the Gmail n8n node to interact directly with the Gmail API, fetching all spam emails and then permanently deleting them, ensuring your email account maintains optimal hygiene. Implementing this n8n workflow not only saves time but also guarantees consistent maintenance, making it one of the most useful n8n templates for personal productivity.

How it Works

This automation operates in four sequential steps, initiated by the custom n8n trigger:


  1. Scheduled Activation: The n8n workflow begins execution automatically via the 'Monthly Trigger (1st Day)' n8n trigger. This configuration is set to run precisely on the first day of every month at 6 AM.

  2. Fetch Spam: The subsequent Gmail n8n node executes an getAll operation, specifically targeting emails labeled SPAM. It retrieves the IDs of every single message currently residing in the spam folder.

  3. API Rate Limit Protection: A brief 'Pause Before Deletion (5s)' n8n node is included. This wait step ensures a short delay, which is good practice to prevent potentially hitting Gmail's API rate limits when processing a very large number of emails.

  4. Permanent Deletion: Finally, the 'Delete Fetched SPAM Emails' Gmail n8n node receives the list of message IDs. Using the delete operation and referencing the ID of each item from the previous step (using the expression ={{ $json.id }}), it permanently removes all spam emails from the account. This completes the monthly cleanup cycle for this essential n8n workflow.

Installation Guide

To use this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code and paste it into your n8n instance using the 'New' menu -> 'Import from JSON'. This imports the core structure of the n8n workflow.

  2. Credentials Setup (Gmail): You must configure the required credentials for the Gmail n8n node. Click on both 'Fetch SPAM Emails (Gmail)' and 'Delete Fetched SPAM Emails' nodes.

  3. OAuth2 Connection: Select or create a new Gmail OAuth2 credential. Ensure the required scopes (read/write access to mail) are granted, as this n8n workflow requires the ability to list and permanently delete messages.

  4. Activation: Once credentials are set, activate the n8n workflow by toggling the 'Active' switch in the top left corner. The 'Monthly Trigger (1st Day)' n8n trigger will handle all future executions.

Node Details

This n8n workflow utilizes core system nodes and the specialized Gmail n8n node:

Monthly Trigger (1st Day) (n8n-nodes-base.scheduleTrigger)
Function: Acts as the primary n8n trigger, initiating the automated clean-up.
Key Configuration: Set to run once per month, specifically on the 1st day of the month.

Fetch SPAM Emails (Gmail) (n8n-nodes-base.gmail)
Function: Communicates with the Gmail API to retrieve message identifiers.
Key Configuration: Operation is getAll. Filters are set to target only labelIds: ["SPAM"]. Return All is set to true to ensure every single spam email ID is captured for the next n8n node.

Pause Before Deletion (5s) (n8n-nodes-base.wait)
Function: A simple control flow n8n node that introduces a delay in the n8n workflow execution.
Key Configuration: The duration is set implicitly to provide a short pause before proceeding to the mass deletion.

Delete Fetched SPAM Emails (n8n-nodes-base.gmail)
Function: Performs the destructive action of permanently deleting the retrieved emails.
Key Configuration: Operation is delete. The Message ID parameter uses an expression (={{ $json.id }}) to dynamically pass the ID of each individual email item received from the 'Fetch SPAM Emails (Gmail)' n8n node.

Related n8n Workflows

Free

Nodes: 4 Nodes
Updated: December 26 2025
View all
Created by

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

Featured*