function Intialize() {
return;
}
function Install() {
ScriptApp.newTrigger("purgeGmail")
.timeBased().everyMinutes(10).create();
}
function Uninstall() {
var triggers = ScriptApp.getScriptTriggers();
for (var i=0; i<triggers.length; i++) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
function purgeGmail() {
var search = "to:[email protected]";
var threads = GmailApp.search(search, 0, 100);
for (var i=0; i<threads.length; i++) {
var thread = threads[i];
thread.moveToTrash();
}
}
- Go to https://script.google.com and create a new script
- Copy the above to the script input
- Click the save icon
- Click the "Run" menu
- Click the "Install" submenu entry
- Wait a few days, it will delete 100 messages each 10 minutes
I wanted a script to remove emails that are older than a certain time. I get notifications from Jira and other services which I want to receive but I don't want to keep them. I've modified the function to allow an array of search terms.
I didn't see anything in the documentation about moveThreadsToTrash only supporting 100 messages at a time but I could be wrong.The docs say the call will fail if there are "too many threads." When you run the script it comes back with an error stating there is a max of 100 threads.