删除Gmail中的所有Gmail促销

时间:2019-09-08 12:17:56

标签: google-apps-script gmail http-status-code-404 gmail-api

我正在尝试使用我找到并修改的以下代码删除“促销”标签中的所有电子邮件,但出现错误

"Response Code: 404. Message: Not Found. (line 4, file "Code")Dismiss"

这是我正在使用的代码:

function deleteForever(userId) {
  var threads = GmailApp.search("category:social");
  for (var i = 0; i < threads.length; i++) {
    Gmail.Users.Messages.remove(userId, threads[i].getId());
  }
}

1 个答案:

答案 0 :(得分:1)

问题:

  • 提供thread id来删除,而不是向接受message id的方法提供message id。

解决方案:

  • 如果要按ID删除线程,请改用Threads.remove

警告:

  • 立即使用Threads.remove并永久删除指定的线程。此操作无法撤消。改用Threads.trash

摘要:

Gmail.Users.Threads.remove("me", threads[i].getId()); //☠️Permanently and irrevocably deletes the thread☠️

参考文献: