首页 > 解决方案 > 谷歌脚本触发了太多电子邮件

问题描述

每次在谷歌工作表上更新一行时,我都会尝试触发一封电子邮件。但是,添加 1 行时会触发太多电子邮件。我正在使用的代码如下。

`

function valueCheck(e) {
  var ss= SpreadsheetApp.getActive();
  var sheet1= ss.getSheetByName("Applications");
  var lastRow = sheet1.getLastRow();
  var companyName = 2;
  var applicationLink=3;
  var com = sheet1.getRange(lastRow, companyName).getValue();
  var link1= sheet1.getRange(lastRow, applicationLink).getValue();
  if (link1)
  {
    MailApp.sendEmail("r***@gmail.com","Apply to "+com,"link to apply:"+link1);
}
}

标签: google-apps-scriptgoogle-sheets

解决方案


尝试这样的事情:

function onMyChange(e) {
  const sh=e.source.getActiveSheet();
  //e.source.toast('Entry');//for debugging
  //sh.getRange('A1').setValue(JSON.stringify(e));//You use this to learn more about the event object
  if(sh.getName()=='Sheet1' && e.changeType=="EDIT") {//I assume you're using EDIT changeType
    //e.source.toast('Sheet1')//for debugging
    //do your stuff in here
  }
}

我不知道你想使用什么 changeType 。


推荐阅读