This script will help you delete old emails inside your Gmail Mailbox by moving them to trash. It deletes emails based on the Gmail Queries mentioned inside searches. The default script will delete the emails that are-
- Inside default Gmail Cetegories
- Unread
- Not starred
- Not in Trash
- Don't have attachments
- Not marked important
- Older than 7 days
The default filters are kept in place to keep your important emails safe. So, please ensure that your important emails don't match all the above criteria.
For example, I star all my important email threads which won't be deleted by the script.
Google permanently deletes mails from Trash after 30 days.
You can add a gmail query.More info on Gmail Queries Given below-
The script is efficient version of the code snippet from following blog post-
A cleaning robot for your Gmail inbox
Create a Google Apps Script project at https://script.google.com/ using the contents of GmailCleaner.gs.
Under Edit > Current project's triggers, schedule the script to run on a recurring basis. (e.g. "Time-driven", "Minutes timer", and "Every 15 minutes")
To continue learning about how to extend Google Docs, Sheets and Forms with Apps Script, take a look at the following resources:
- Omkar Marathe - Initial work - Omkar
If you've found an error in this sample, please file an issue here
Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub.
General questions about Apps Script can be asked on StackOverflow: google-apps-script on StackOverflow
General Apps Script bug reports or feature requests should be directed to the Apps Script Issue Tracker: google-apps-script-issues
This project is licensed under the MIT License - see the LICENSE file for details