簡體   English   中英

谷歌腳本發送電子郵件功能不起作用

[英]Google Script Send email function Not working

使用谷歌腳本,我需要創建一個函數,當沿 D 列新添加的單元格小於 8 時發送電子郵件通知。但是,當我測試輸入小於甚至大於 8 的值時,我沒有收到電子郵件。

function sendEmailReport() {
  var ss_link = 'Google Spreadsheet URL';
  var ss = SpreadsheetApp.openByUrl('Google Spreadsheet URL').getSheetByName("Sheet Name").getRange("D:D"); //get column D in a specified sheet
  var row = ss.getLastRow(); //get the last row on the column D. The last row contains newly added row.
  var value = ss.getValue(); // then get the value of the cell at the last row along column D.
  //if the value in the newly added row is less than 8. I want to send an email
  if (value < 8) {
    MailApp.sendEmail({
      to: "Email Address",
      subject: "Sample Subject",
      body: "Sample Body" + ss_link
      name: 'Department ABC'
    });
  }
}

這是固定代碼:

function sendEmailReport() {
  var ss_link = 'Google Spreadsheet URL';
  var ss = SpreadsheetApp.openByUrl('Google Spreadsheet URL').getSheetByName('Sheet Name');
  var row = ss.getLastRow();
  var value = ss.getRange('D'+row).getValue();

  //if the value in the newly added row is less than 8. I want to send an email
  if (value < 8) {
    MailApp.sendEmail({
      to: 'Email Address',
      subject: 'Sample Subject',
      body: 'Sample Body' + ss_link
      name: 'Department ABC'
    });
  }
}

這是一個“靜態”代碼:每次發送電子郵件時都必須手動運行它。 如果您需要自動運行它,則需要一個更復雜的解決方案,其中包含可安裝的觸發器onEdit()等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM