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
STARREDwithin messages. - Threads without starred emails go to a Gmail node that removes the
INBOXlabel, 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
- Download the workflow file from this page using the Download button.
- In the n8n editor, click on ‘Import from File’ and upload the downloaded workflow.
Step 2: Configure Credentials
- Add your Gmail account credentials in the Gmail nodes using OAuth2.
- Update any IDs, emails, or labels if your Gmail setup differs.
Step 3: Test the Workflow
- Manually run the workflow once to check for errors and make sure emails fetch correctly.
Step 4: Activate for Production
- Turn on the workflow using the toggle switch at the top right in n8n.
- 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.
