这是我目前正在尝试用于基于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);
}
}
我收到的当前错误消息是“参数(number [],String,String)与MailApp.sendEmail的方法签名不匹配。(第15行,文件”
这个想法是: 当单元格C2在270和310之间时,发送电子邮件“琥珀色警告” 当单元格C2高于310时,发送电子邮件“红色警告” 当单元格C2小于270时,没有电子邮件
希望它将附加到触发器上,以每15分钟安排一次
任何有关如何组合两封电子邮件(或每封电子邮件都有一个代码)的帮助将不胜感激。
答案 0 :(得分:0)
似乎您的“ emailAddress”参数是一个数字数组(number []),因为您收到的错误是这样的。
尝试使用getValue()
(如果它是一个地址),或者通过执行getValues()[0]
获得2D数组的getValues()
的第一个值。
根据您的选择,在调用emailAddress
之前将其分配给MailApp.sendEmail()
变量。
答案 1 :(得分:-1)
尝试遵循documentation中的步骤 因为它清楚地解释了所有内容以及如何通过应用脚本发送电子邮件