Delete a bunch of emails (thousands) by tag from gmail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function batchDelete() { | |
var batchSize = 10; // Process up to 10 threads at once | |
for (i = 175; i > 0; i--) { | |
var threads = GmailApp.search('label:outbound older_than:' + i + 'd'); | |
for (j = 0; j < threads.length; j += batchSize) { | |
GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize)); | |
// Logger.log('finished move %d', j); | |
} | |
} | |
} |
works for me, had to authorize first
had a label with over 100,000 emails and no other solution worked, although the script times out after a few minutes it manages to delete a few thousand each time. I've slowly upped the batch size and so far that helps, haven't reached a batch size limit yet
function batchDelete() {
var batchSize = 100; // Process up to 10 threads at once
for (i = 175; i > 100; i--) {
var threads = GmailApp.search('label:outbound older_than:' + i + 'd');
for (j = 0; j < threads.length; j += batchSize) {
GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize));
//Logger.log('finished move %d', j);
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
currently not working for me because...
Cannot connect to Gmail (line 5, file "batch-delete")