
When you open Gmail every day, are you always flooded with a bunch of “promotions”, “new product push” and “newsletter”? If you delete them manually, there are too many emails; if you don’t, you’re afraid you won’t find important emails
If you have the same problem, today I will share an n8n workflow for “automatically cleaning up Gmail subscription emails”. You can delete junk emails in batches with just one click without writing any code, and you can also avoid important information accurately.
What can this workflow do for you?
In short, it automatically filters and deletes “low-value subscription/marketing emails” in Gmail while strictly protecting emails containing important information. The core logic can be broken down into three steps:
❶ Delete only “subscription/marketing” emails
It will precisely target emails containing the keyword “unsubscribe” – almost all of these emails are from subscribed accounts, e – commerce promotions, and advertising push (after all, who would put an “unsubscribe” link in a serious email? )
But “unsubscribe” is not enough. It will automatically exclude two types of emails:
- Exclude “Chats” (the content under the Chats tab in Gmail to avoid accidentally deleting instant communication records);
- Exclude emails containing “license/key/password” (such as software licenses, API keys, password reset notifications, etc. It would be troublesome if you delete them! )
❷ Manual trigger
Many people are afraid that “Auto Clean” will accidentally delete emails? You don’t have to worry about this workflow at all – it must be manually clicked “Execute” to start, and it won’t run secretly at ordinary times.
You can take 1 minute every week/month to confirm that you have accumulated a bunch of ads recently, and then manually trigger the cleaning. The whole process is controllable, just as reassuring as pressing the “cleaning button”.
❸ Delete in batches
The Gmail API has call limits, and deleting too many emails at once can easily cause “stuttering”. The workflow will automatically divide the filtered email IDs into “100 per batch” and delete them slowly in batches to avoid being throttled due to too frequent requests.
After deletion, the content will be moved to the “Trash Bin” by default (not permanently deleted). If you accidentally delete something, you can retrieve it from the trash bin. We’ve got you covered!
Want to build one? You can configure it in 3 steps
❷ Configure the core nodes (4 nodes are enough)
n8n workflows are made up of “nodes”. This cleanup tool only requires four nodes, connected like building blocks:
- Manually trigger the node : As a switch, it starts only when you click “Execute”;
- Gmail Filter Node : Fill in the search criteria (i.e.,
-in:chats unsubscribe -license -key -password
) to get the IDs of the emails that meet the criteria; - Batch processing node: Set to delete 100 emails per batch (default value, no need to change);
- Delete Node: Receive the email ID and call the Gmail API to delete it (don’t worry, it will be deleted to the trash).
❸ Test + Run
After the configuration is completed, first select “Test Execution” to see if the filtered email IDs are correct (for example, if any important emails are accidentally selected). After confirming that there is no problem, click “Execute Workflow” and wait for it to be deleted in batches.
Why recommend using n8n for this?
Some may say, “Gmail already has built-in filtering rules, so why use n8n?”
It’s true that Gmail filters can automatically archive emails, but the advantage of n8n lies in “more flexible filtering + manual control + batch deletion”:
- More refined filtering rules: Gmail’s “exclude keywords” logic is relatively basic. n8n can directly use Gmail’s advanced search syntax (such as
-in:chats
to exclude chats), combining more complex conditions; - Batch deletion is safer: Gmail allows you to select up to 50 emails at a time for manual deletion, while n8n can automatically process 100 emails per batch, making it more efficient;
- It’s not just about clearing emails. After learning n8n, you can also build other automation tools, such as “Automatically sync Gmail attachments to Cloud Drive”, “Send important email summaries to Notion”, and even automate workflows. It’s highly cost-effective!