'Google Script to empty emails in trash folder

I was using the below google app script to delete emails automatically from my trash folder. for some reason, this is no longer deleting the emails however the trigger dashboard shows the script executed successfully. can someone help to modify the script ? thanks in advance.

function removeMyTest2() {
var mymail = "me";
var mylabel = "del";
var permanentlyRemoveMyLabel = true;
var pageToken;
do {
    var threadList = Gmail.Users.Threads.list('me', {
    q: 'in:trash' + mylabel,
    pageToken: pageToken
    });
    if (threadList.threads && threadList.threads.length > 0) {
        threadList.threads.forEach(function(thread) {
        Logger.log('id: %s snippet: %s', thread.id, thread.snippet);
        if (permanentlyRemoveMyLabel) {
            Gmail.Users.Threads.remove(mymail, thread.id);
            Logger.log('id: %s snippet: %s REMOVED', thread.id, thread.snippet);
        }
    });
   }
   pageToken = threadList.nextPageToken;
   } while (pageToken);
}


Solution 1:[1]

Try this:

I believe you were missing the label key.

function removeMyTest2() {
  var pageToken=null;
  do {
    var threadList=Gmail.Users.Threads.list('me', {q:'in:trash label:del',pageToken:pageToken});
    if (threadList.threads && threadList.threads.length>0) {
      threadList.threads.forEach(function(thread) {
        Gmail.Users.Threads.remove("me", thread.id);
      });
    }
    pageToken=threadList.nextPageToken;
  } while (pageToken);
}

I tested this with another label and it works fine

I needed this scope: https://mail.google.com/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1