简体   繁体   English

使用带有 gmail 搜索词和工作表中的多行的 Google 表格删除带有脚本的 gmail,以进行批量处理

[英]Delete gmails with script using google sheet with gmail search terms and multiple rows in sheet for bulk processing

This function will delete ONE (1) email matching search term defined in A2 (And it works):此 function 将删除 A2 中定义的一 (1) 个 email 匹配搜索词(并且有效):

function deleteEmail() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheets()[0];
  const searchTerm = sheet.getRange("A2").getValue();
  GmailApp.search(searchTerm).map(thread => thread.moveToTrash()); 
}

However, creating individual script functions for individual search terms with individual triggers would take forever to do...但是,为带有单独触发器的单独搜索词创建单独的脚本函数将需要很长时间才能完成......

I tried simply to use A2:A, but unfortunately that was not working.我尝试简单地使用 A2:A,但不幸的是这不起作用。

function deleteEmail() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheets()[0];
  const searchTerm = sheet.getRange("A2:A").getValue();
  GmailApp.search(searchTerm).map(thread => thread.moveToTrash()); 
}

How can one delete gmails with a script using google sheet scripts with gmail search terms and multiple rows in a sheet for bulk processing?如何使用带有 gmail 搜索词和工作表中的多行进行批量处理的谷歌工作表脚本删除 gmail?

3 parameters are needed: sender, subject and older_than, like this:需要 3 个参数:sender、subject 和 old_than,如下所示:

from:(@google.com) subject:Notification older_than:3d来自:(@google.com)主题:通知old_than:3d

Perhaps this will work也许这会奏效

function deleteEmail() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheets()[0];
  const terms = sheet.getRange("A2:A" + sheet.getLastRow()).getValues();
  terms.forEach(s => Gmail.App.search(s).forEach(thread => thread.moveToTrash()))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将Gmail拉入Google表格 - Pull Gmails into a Google Sheet 为在不同工作表上找到的多个搜索词运行脚本 - Running script for multiple search terms found on different sheet Google脚本可将多行同时移动到另一张工作表-归档行并完成删除 - Google Script to Move Multiple Rows Simultaneously to Another Sheet - Archive Rows and Delete Completed 在工作表之间传输大量行的更有效方法 - Google Apps 脚本 - A more efficient way of transferring bulk amount of rows from sheet to sheet - Google Apps Script 使用工作表和应用程序脚本在谷歌文档中批量查找和替换 - bulk find and replace in google docs using sheet and app script 使用G脚本自动将Google表格附加到Gmail的电子邮件中 - Attaching Google Sheet to emails from Gmail automatically using G Script 您无法删除工作表 Google Sheets Script 上的所有行 - You can't delete all the rows on the sheet Google Sheets Script 工作表受到保护时,Google App Script 删除行不起作用 - Google App Script delete rows not working while sheet is protected 删除工作表中的行(Google 脚本) - Delete Row in sheet (Google Script) 使用 Apps 脚本从 Google 表格中的另一张表格中删除包含值的行 - Delete rows containing value from another sheet in Google Sheets using Apps Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM