首页 > 解决方案 > 收到新的 Google 表单提交后,如何忽略向具有价值的行发送电子邮件?

问题描述

当有人新提交他的信息时,我想要使我的脚本忽略发送合并电子邮件到我使用 Google 表单收集的以前电子邮件的功能。

这是我正在使用的脚本:

function sendMail() {
  const emailTemp = HtmlService.createTemplateFromFile("email");
  const sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("form1");
  const startRow = 2
  const data = sh.getRange(startRow, 2, sh.getLastRow() - 1, sh.getLastColumn() - 1).getValues();
  data.forEach((row, i) => {
    emailTemp.fullname = row[1];
    emailTemp.phone = row[2];
    let htmlMessage = emailTemp.evaluate().getContent();
    let emailSent = row[6];
    if (emailSent != "EMAIL_SENT") {
      GmailApp.sendEmail(row[0],"Thank you!","Your email doesn't support HTML.",{ name: "Email App", htmlBody: htmlMessage });
      sh.getRange(startRow + i, 6).setValue("EMAIL_SENT");
    }
  });
} 

我想忽略列F中具有EMAIL_SENT值的所有 例子

谢谢你。

标签: javascriptgoogle-apps-scriptgoogle-sheets

解决方案


这就是这条线的用途 if (emailSent != "EMAIL_SENT") {

let emailSent = row[6];应该是这个let emailSent = row[4];

根据您的原始问题,您的行从第 2 列开始。


推荐阅读