Automate Gmail Inbox Cleanup with n8n at Midnight

Tired of cluttered Gmail inboxes? This n8n workflow automates your inbox cleanup by archiving all non-starred emails every workday at midnight, keeping your important emails starred and accessible. Save hours daily and reduce manual sorting errors.
gmail
scheduleTrigger
filter
+2
Workflow Identifier: 1504
NODES in Use: Schedule Trigger, Gmail, Filter, Item Lists, Sticky Note
Automate Gmail cleanup with n8n and Gmail

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow cleans up Gmail inboxes every workday at midnight. It finds all emails from the past 24 hours. It keeps starred emails in the inbox. It archives all other emails by removing the Inbox label. This helps users focus only on important emails marked with a star.

The workflow runs automatically without needing manual work. It makes inboxes less messy and saves time spent sorting emails.


Who should use this workflow

This workflow is for anyone with a busy Gmail inbox full of many emails. Especially useful for people receiving lots of newsletters or promotions.

It suits users who want to keep only starred emails visible and archive all others daily. It works well for professionals who want to save time and keep inbox organized.


Tools and services used

You can use self-host n8n for more control and privacy if needed.


Inputs, Processing, and Output

Inputs

  • Emails received in the Gmail inbox during the last 24 hours.

Processing Steps

  • The workflow uses the Schedule Trigger node to run every Monday to Friday at midnight using the cron expression 0 0 * * 1-5.
  • A Gmail node fetches all email threads from the inbox with the query label:inbox receivedBefore:={{ $now.minus({days: 1}) }}.
  • Another Gmail node retrieves full details of each thread, including individual messages.
  • A Filter node checks if threads have any starred messages by searching for the label STARRED within messages.
  • Threads without starred emails go to a Gmail node that removes the INBOX label, archiving the entire thread.
  • For threads with starred emails, an Item Lists node splits messages. Then each message without the star is archived individually to keep inbox focused on important starred emails only.

Output

Inbox with only starred emails visible. All other emails are archived automatically. Cleaner inbox, saved time, and less risk of missing important messages.


Beginner step-by-step: How to use this workflow in n8n

Step 1: Import Workflow

  1. Download the workflow file from this page using the Download button.
  2. In the n8n editor, click on ‘Import from File’ and upload the downloaded workflow.

Step 2: Configure Credentials

  1. Add your Gmail account credentials in the Gmail nodes using OAuth2.
  2. Update any IDs, emails, or labels if your Gmail setup differs.

Step 3: Test the Workflow

  1. Manually run the workflow once to check for errors and make sure emails fetch correctly.

Step 4: Activate for Production

  1. Turn on the workflow using the toggle switch at the top right in n8n.
  2. The workflow will now run automatically every weekday at midnight.

This simple setup helps you clean your inbox without rebuilding or coding.


Customization ideas

  • Adjust the Schedule Trigger node’s cron expression to run at other times or include weekends.
  • Modify the Gmail query to fetch emails from different labels or use filters like sender or subject.
  • Add more labels to remove or keep when archiving to better organize emails.
  • Insert Email or Slack nodes after archiving to notify about cleaned emails count or summary.

Common problems and fixes

  • No emails fetched: May happen if Gmail credentials are wrong or query syntax is incorrect. Fix by checking OAuth2 setup and query format.
  • Workflow not triggering: Check the cron expression is valid and the workflow is turned on.

Summary of results

✓ Inbox only shows starred important emails every morning.
✓ All other emails are archived automatically without deleting.
✓ Saves about 30 minutes of manual email sorting each workday.
✓ Reduces chance of missing critical emails buried in clutter.
✓ Runs quietly in background every weekday at midnight.


Automate Gmail cleanup with n8n and Gmail

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

The Gmail node fetches email threads from the inbox received in the last 24 hours using the query ‘label:inbox receivedBefore:={{ $now.minus({days: 1}) }}’.
Starred emails remain in the inbox and are not archived. The workflow filters threads containing starred messages and keeps them visible.
Yes, the Schedule Trigger node uses a cron expression that can be modified to run the workflow at different times or days.
Users should add Gmail OAuth2 credentials to the Gmail nodes, update any Gmail IDs if needed, test the workflow, and activate it for automatic runs.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.