繁体   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