permanently delete only one gmail message from a thread using a google script

后端 未结 1 1666
情话喂你
情话喂你 2020-12-22 11:44

I want to permanently delete a Gmail message inside a thread already in the trash.

I merged a few scripts around there, so I can delay and track emails. It works by

相关标签:
1条回答
  • 2020-12-22 12:24

    i finally made it trough an http request:

    function cleanUp2() {
      var threads = GmailApp.search("in:trash is:draft");
      Logger.log(threads.length);
    
      var userId = 'xxxxx@gmail.com';
      var options = {
       'method' : 'delete',
       'muteHttpExceptions': true
     };
    
      for (var i = 0; i < threads.length; i++) {
        var messages = threads[i].getMessages();
        Logger.log(messages.length);
    
        for (var j = 0; j < messages.length; j++){
          if (messages[j].isDraft()){
            Logger.log('id msg: ' + messages[j].getId());
            var url = 'https://www.googleapis.com/gmail/v1/users/' + userId + '/messages/' + messages[j].getId();
            var response = UrlFetchApp.fetch(url,options);
            Logger.log(response);            
          }    
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题