-1

per a blog, I've tried running the following script to bulk delete, but it keeps timing out (after being debugged). any suggestions?

    function deleteOldEmail() {
        var batchSize = 100
        while (true) {
         var threads = GmailApp.search('is:unread emails: after:2016/12/31 before:2018/1/1');
         for (j = 0; j < threads.length; j+=batchSize) {
          GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize));
          }
       }
    }

1 Answers1

0

Google Apps Script has a execution time limit, 6 minutes for @gmail.com / free accounts and 30 mins for G Suite accounts.

The simpler thing to do is to set a timer that before reaching the limit, it will create a trigger to call the same function a bit later repeating this until all the threads were deleted.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166