Scheduled Gmail SPAM Cleanup - n8n Workflow

Use this efficient n8n workflow to schedule weekly execution to find and permanently delete all SPAM emails from your Gmail account, ensuring an automatically clean inbox.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users overwhelmed by accumulated junk and SPAM emails.
System administrators or individuals looking to maintain strict email storage limits.
Anyone seeking a reliable, automated digital hygiene solution using an n8n template.
n8n users who want an example of a scheduled n8n workflow.

Overview

Managing SPAM is a constant chore that consumes time and storage space. This purpose-built n8n workflow transforms this manual process into a set-and-forget automation. By leveraging the built-in Schedule n8n trigger, this solution guarantees that your SPAM folder is emptied on a consistent, predefined schedule, such as every Sunday night. This n8n workflow uses the Gmail n8n node's ability to fetch all messages tagged as SPAM and then iteratively deletes them, providing significant value in maintaining a clean and efficient inbox without manual intervention. This practical n8n template is quick to deploy and immediately effective.

How it Works

This efficient n8n workflow starts with a scheduled n8n trigger. The default configuration sets the 'Trigger at Sunday midnight' n8n node to run every week.


  1. Trigger Execution: The Schedule Trigger n8n node initiates the entire n8n workflow sequence based on its weekly rule.

  2. Retrieve SPAM: The workflow immediately moves to the 'Get all SPAM emails' Gmail n8n node. This node executes a getAll operation, specifically filtering for messages with the SPAM label ID, and uses the returnAll setting to ensure all existing junk messages are retrieved as separate items.

  3. Iterative Deletion: Finally, the flow connects these retrieved items to the 'Delete SPAM emails' Gmail n8n node. This final n8n node performs a delete operation. Crucially, it uses an expression (={{ $json.id }}) to dynamically target and delete the specific message ID passed from the previous Gmail n8n node, effectively purging all identified SPAM messages from your account. This entire n8n workflow runs autonomously.

Installation Guide

To deploy this n8n template, follow these steps:


  1. Import: Copy the provided JSON code and import it directly into your n8n instance using the 'New' menu and selecting 'Import from JSON'.

  2. Credentials Setup: Locate the two Gmail n8n nodes ('Get all SPAM emails' and 'Delete SPAM emails'). You will need to set up or select existing OAuth2 credentials for your Gmail account. Ensure the credentials have sufficient scope to read message labels and permanently delete messages.

  3. Configure Trigger: Review the 'Trigger at Sunday midnight' n8n trigger node. Adjust the schedule parameters if you prefer a different running time (e.g., daily, or a specific day/time).

  4. Activation: Once credentials are set and the n8n trigger schedule is confirmed, save and activate the n8n workflow.

Node Details

Schedule Trigger (Trigger at Sunday midnight):
Function: Acts as the primary n8n trigger, defining when the n8n workflow executes.
Key Configuration: Set to run once every week (interval: [{"field":"weeks"}]). This can be customized by the user.
Gmail Node (Get all SPAM emails):
Function: Connects to Gmail to fetch a list of all messages currently sitting in the SPAM folder.
Key Configuration: Operation is getAll. Filters are set to labelIds: ["SPAM"]. returnAll is set to true to ensure comprehensive retrieval of all items, enabling the downstream delete action.
Gmail Node (Delete SPAM emails):
Function: Takes the list of message IDs from the previous node and executes a permanent deletion operation for each item.
* Key Configuration: Operation is delete. The messageId is dynamically pulled using the expression ={{ $json.id }} ensuring the correct email is targeted and removed by this n8n node.

Related n8n Workflows

Free

Nodes: 3 Nodes
Updated: December 26 2025
View all
Created by
Bao Duy Nguyen
Bao Duy Nguyen

Featured*