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

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

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

  • n8n account: Platform to build and run the workflow.
  • Gmail with OAuth2 credentials: For secure email access and management.
  • Schedule Trigger node: To start workflow at midnight on weekdays.

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.


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 Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free