-1

这是我目前尝试使用的代码,用于根据 C2 的单元格值实现电子邮件(请参见下面的 Google 表格截图)。

function amberwarning() {
  // Fetch the combined flow value
  var combflowrange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FloodEWS").getRange("C2"); 
  var combflow = combflowrange.getValue();
  // Check combined flow value
  if (270 < combflow < 310){
    // Fetch the email address
    var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email").getRange("A2");
    var emailAddress = emailRange.getValues();
    
    // Send Alert Email.
    var subject = 'Amber warning';
    var message = 'It is possible that the Egger site will experience flooding in the coming hours. The advice is to be prepared to take action as combined river flows can increase very quickly during storms. Please keep up to date with the latest river levels for Hexham at <https://flood-warning-information.service.gov.uk/station/9006>. The latest flood warnings from the Environment Agency for Hexham are here <https://flood-warning-information.service.gov.uk/warnings?location=+hexham>. The latest MetOffice weather forecast can be found here <https://www.metoffice.gov.uk/weather/forecast/gcy2xzrne#?>. Please use all available information to inform your decision making. You will keep receiving an email as per each refresh of the latest data. The current combined flow from the North and South Tyne is' + combflow;
    
    MailApp.sendEmail(emailAddress,subject,message);
    }
}

我收到的当前错误消息是“参数(数字 [],字符串,字符串)与 MailApp.sendEmail 的方法签名不匹配。(第 15 行,文件”

想法是:当单元格 C2 介于 270 和 310 之间时,发送电子邮件“琥珀色警告” 当单元格 C2 高于 310 时发送电子邮件“红色警告” 当单元格 C2 小于 270 时,不发送电子邮件

这有望附加到触发器上,每 15 分钟安排一次

任何有关如何组合两封电子邮件(或每封电子邮件都有一个代码)的帮助将不胜感激。

在此处输入图像描述

4

2 回答 2

0

看来您的“emailAddress”参数是一个数字数组(number []),因为您收到的错误是这样说的。

getValue()如果它是单个地址,请尝试使用,或者getValues()通过getValues()[0].

无论您选择哪个,在调用之前将其分配给您的emailAddress变量MailApp.sendEmail()

于 2020-08-27T08:56:22.420 回答
-1

尝试按照文档中的步骤进行操作, 因为它清楚地解释了所有内容以及如何通过 app-script 发送电子邮件

于 2020-08-26T17:18:02.963 回答