如何停止在谷歌表格腳本中發送重複的電子郵件

我有以下腳本用於在谷歌表格中發送電子郵件。“Email_Sent”插入第 36 列以防止發送重複的電子郵件。出於某種原因,腳本會重複發送電子郵件。請有人幫助告訴我為什麼腳本不能正常工作?謝謝

/**
 * Sends emails from spreadsheet rows.
 */
function sendEmails() {
  const ss = SpreadsheetApp.getActive();
  const dsh = ss.getSheets()[0];//repl with getshbyname
  const drg = dsh.getRange(2, 1, dsh.getLastRow() - 1, 36);
  const vs = drg.getValues();
  const tsh = ss.getSheets()[1];//repl with getshbyname
  const tmpl = tsh.getRange('A1').getValue();
  vs.forEach((r,i) => {
    let emailSent = r[35]; 
    let status = r[10];  
    if (status == 'PRICE ONLY' && emailSent != 'EMAIL_SENT') { 
    MailApp.sendEmail(r[9], 'SUPERMIX QUOTATION',fillInTemplateFromObject(tmpl, r) );//if last paramenter is the options object then you are missing the  null for the body. but since fillInTemplateFromObject is undefined I can not know that
    dsh.getRange(2 + i, 36).setValue('EMAIL_SENT');
    SpreadsheetApp.flush();
    }
  });
}
/**
 * Replaces markers in a template string with values define in a JavaScript data object.
 * @param {string} template Contains markers, for instance ${"Column name"}
 * @param {object} data values to that will replace markers.
 *   For instance data.columnName will replace marker ${"Column name"}
 * @return {string} A string without markers. If no data is found to replace a marker,
 *   it is simply removed.
 */
function fillInTemplateFromObject(tmpl, data) {
  var email = tmpl;
  // Search for all the variables to be replaced, for instance ${"Column name"}
  var templateVars = tmpl.match(/\$\{\"[^\"]+\"\}/g);

  // Replace variables from the template with the actual values from the data object.
  // If no value is available, replace with the empty string.
  for (var r = 0; templateVars && r < templateVars.length; ++r) {
    // normalizeHeader ignores ${"} so we can call it directly here.
    var variableData = data[normalizeHeader(templateVars[r])];
    email = email.replace(templateVars[r], variableData || '');
  }

  return email;
}
庫柏

嘗試這個:

function sendEmails() {
  const ss = SpreadsheetApp.getActive();
  const dsh = ss.getSheets()[0];//repl with getshbyname
  const drg = dsh.getRange(2, 1, dsh.getLastRow() - 1, 36);
  const vs = drg.getValues();
  const tsh = ss.getSheets()[1];//repl with getshbyname
  const tmpl = tsh.getRange('A1').getValue();
  vs.forEach((r,i) => {
    let emailSent = r[35]; 
    let status = r[10];  
    if (status == 'PRICE ONLY' && emailSent != 'EMAIL_SENT') { 
    MailApp.sendEmail(r[?], 'SUPERMIX QUOTATION',fillInTemplateFromObject(tmpl, r) );//if last paramenter is the options object then you are missing the  null for the body. but since fillInTemplateFromObject is undefined I can not know that
    dsh.getRange(2 + i, 36).setValue('EMAIL_SENT');
    }
  });
}

您的代碼示例有一些未定義的變量和/或對象,因此無法提供完整的解決方案。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

加入來自多列的數據並從谷歌腳本發送電子郵件警報

Google Apps 腳本:發送 docx 電子郵件附件

腳本在運行代碼時不發送電子郵件

如何在發送電子郵件的 Google 應用腳本的 html 服務中設置背景圖像?

我正在使用模板發送帶有谷歌表格的電子郵件

如何創建基於日期觸發電子郵件的腳本?

嘗試根據谷歌表格中的條件為觸發郵件創建腳本

Apps 腳本:根據不同列中指定的日期發送 html 電子郵件

在 React Native 中發送電子郵件

如何在 Django 中發送每週預定的電子郵件

是否可以將 Google 表格中的多張表格作為電子郵件附件發送?

Google 應用程序腳本 - 通過單擊鏈接或使用彈出窗口每行發送一封電子郵件?

用於電子郵件通知的 PowerShell 腳本

如何在php中創建臨時文件以通過電子郵件發送?

如何更改 URL 中的圖像並仍然確保發送的舊電子郵件不受影響?

Studio Flow -> 發送消息 -> 功能(電子郵件)

我的腳本沒有根據計時器觸發所有電子郵件

如何使用 Amazon SES 使用 reactjs 發送電子郵件

在 Laravel 8 中發送沒有環境變量的電子郵件

在 Python 中發送帶有多個附件的電子郵件

在 SuiteScript 中發送帶有正確回复的案例回復電子郵件

將 Excel 文件作為指定 Google 表格的附件通過電子郵件發送

Google App 腳本錯誤 - 無法讀取未定義的屬性“響應”並且無法發送電子郵件:沒有收件人

PHP 郵件功能通過電子郵件發送垃圾郵件(gmail 除外)

WordPress插件在網站關閉時向特定電子郵件地址發送電子郵件?

在 google 腳本的電子郵件中獲取 1 行中的所有列數據

如何在申請後立即自動向求職者發送電子郵件,odoo 14

如何使用現有的 Sendgrid 動態模板與 Jenkins 發送電子郵件

更新重複的電子郵件值,除了 sql 表中的第一個值