Google Apps脚本使用Google的消息ID删除Gmail消息
我有一个我想在Gmail帐户中删除的Google表格中的电子邮件ID列表。我需要一个脚本,该脚本将在运行时删除所有列出的电子邮件。以HTML模式查看Gmail时,ID号来自URL。这是一个示例,180CD026 *** 9177a是我列表中的内容,我需要用来从Gmail中删除消息。到目前为止,我拥有的代码仅在纸张中的ID列表与收件箱中的消息顺序匹配时才能起作用。无论消息在收件箱/列表中的位置,我都需要工作。有人有建议吗?
function myFunction() {
var ss = SpreadsheetApp.getActive();
var sheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1CaptwI0-NCgHfOmn5dT1D2okg2vhu_______________________").getSheetByName("sheet1");
var start = 0;
var threads = GmailApp.getInboxThreads(start, 100);
var range = sheet.getDataRange();
for (var i = 0; i <threads.length; i++){
for (var j = 0; j<6+1; j++){ // replace 4 with the total values in the google sheet
var data = range.getValues();
var iava_value = (data[j][0]);
var message = GmailApp.getInboxThreads(0, 1)[0].getMessages()[0];
// Get its ID
var messageId = message.getId();
console.log(messageId);
//get thread
var thread = GmailApp.getInboxThreads(0,1)[0];
if(messageId==iava_value)
{
thread.moveToTrash();
}
}
}
}
I have a list of email ID numbers in Google Sheets that I would like deleted in my Gmail account. I need a script that will delete all of the listed emails when it is run. The ID number comes from the URL when viewing Gmail in HTML mode. Here is a sample, the 180cd026***9177a is what I have in my list and I need to use to delete the messages from Gmail. The code that I have so far works only if the list of IDs in sheets matches the order of the messages in the inbox. I need something to work no matter where the message is located in the inbox/list. Does anyone have suggestions?
function myFunction() {
var ss = SpreadsheetApp.getActive();
var sheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1CaptwI0-NCgHfOmn5dT1D2okg2vhu_______________________").getSheetByName("sheet1");
var start = 0;
var threads = GmailApp.getInboxThreads(start, 100);
var range = sheet.getDataRange();
for (var i = 0; i <threads.length; i++){
for (var j = 0; j<6+1; j++){ // replace 4 with the total values in the google sheet
var data = range.getValues();
var iava_value = (data[j][0]);
var message = GmailApp.getInboxThreads(0, 1)[0].getMessages()[0];
// Get its ID
var messageId = message.getId();
console.log(messageId);
//get thread
var thread = GmailApp.getInboxThreads(0,1)[0];
if(messageId==iava_value)
{
thread.moveToTrash();
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除其ID在请求数组中的消息,
也许是这样:
Deletes messages whose ids are in the request array
Maybe something like this: