Skip to content

Instantly share code, notes, and snippets.

@kazgoto
Last active December 15, 2021 08:14
Show Gist options
  • Save kazgoto/8e1109295384a2d86f71dcc310642b69 to your computer and use it in GitHub Desktop.
Save kazgoto/8e1109295384a2d86f71dcc310642b69 to your computer and use it in GitHub Desktop.
Gmail で特定ラベルの大量なメールを削除するバッチ関数(どっかで拾ったもの)
function batchDeleteEmail() {
var loopNumber = 50
var batchSize = 100 // Process up to 100 threads at once
var searchSize = 400 // Limit search result to a max of 400 threads. Use this if you encounter the "Exceeded maximum execution time" error
for (i = 0; i < loopNumber; i += 1) {
var threads = GmailApp.search('label:XXXX', 0, searchSize);
for (j = 0; j < threads.length; j += batchSize) {
GmailApp.moveThreadsToTrash(threads.slice(j, j + batchSize));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment