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
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);
}
}
}
}