This article will show you how to configure your Gmail to automatically delete some emails after certain number of days or hours. For example, you may want to keep some email with "daily promotions" only for 24 hours, or you want to keep Amazon newsletters only for few days.
Unfortunately, Gmail built-in filters could not be used for that task because they only work on incoming emails. That is, you cannot automatically process emails already in your inbox.
Described approach uses combination of filter and Google Apps Script - filter applies predefined label to all emails you want to keep only for few days and script is invoked daily, it scans all emails marked with the label and deletes these old enough.
Here's how to install and configure the script:
Open any spreadsheet from you Google drive tab, or create a new empty one
1) Click on a Tools top menu and select Script gallery...
2) Put "newsletters" in a search filed and so search
3) You will find my script named "Remove newsletters older than 24 hours"
4) Install it for your Google account, and after that you will be able to access it from Tools / Script manager menu and open for editing
Unfortunately, Gmail built-in filters could not be used for that task because they only work on incoming emails. That is, you cannot automatically process emails already in your inbox.
Described approach uses combination of filter and Google Apps Script - filter applies predefined label to all emails you want to keep only for few days and script is invoked daily, it scans all emails marked with the label and deletes these old enough.
Here's how to install and configure the script:
Open any spreadsheet from you Google drive tab, or create a new empty one
1) Click on a Tools top menu and select Script gallery...
3) You will find my script named "Remove newsletters older than 24 hours"
4) Install it for your Google account, and after that you will be able to access it from Tools / Script manager menu and open for editing
Now that you have installed the script you need to run it once a day to actually clean up your Inbox and for that you need to set up a trigger:
3) Create a new trigger and configure it as Time driven, Day timer, Midnight to 1am - that will make this script execute daily at midnight on your Gmail account.
Ok, that is almost it... one more small step.
What this script is doing, it scans your inbox looking for emails with specific label - "Newsletters".
All emails with this label older than 24 hours are than moved to trash.
So for this to work you actually need to have this label applied to all your newsletter emails, but that is something easily done with standard Gmail filters - so I will not cover it here.