Skip to content

Instantly share code, notes, and snippets.

@mitar
Created July 11, 2019 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitar/640d8ca15fe7c47850dac16245fc00ab to your computer and use it in GitHub Desktop.
Save mitar/640d8ca15fe7c47850dac16245fc00ab to your computer and use it in GitHub Desktop.
Google Script to move e-mails to Trash
// You can install it at https://script.google.com/
// You can configure it to run every hour to move (eventually) all e-mails under "My Triggers". There are limits
// which prevents it to run for more than 6 minutes. So it is normal that it timeouts. But then there are also
// limits on how many times per day you can run it. So just make a trigger and let it run.
function myFunction() {
while(true){
Logger.log("Searching.");
var threads = GmailApp.search('your search query', 0, 100);
if (!threads.length) {
Logger.log("Nothing found.");
break;
}
Logger.log("Deleting threads.");
GmailApp.moveThreadsToTrash(threads);
Logger.log("Done.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment