【问题标题】:Google Scripts - sending email based on a cell valueGoogle Scripts - 根据单元格值发送电子邮件
【发布时间】:2020-08-26 16:06:46
【问题描述】:

这是我目前尝试使用的代码,用于根据 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 分钟安排一次

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

enter image description here

【问题讨论】:

    标签: email google-apps-script google-sheets


    【解决方案1】:

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

    如果getValue()是单个地址,请尝试使用,或者通过getValues()[0]获取二维数组getValues()的第一个值。

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 谢谢。我只是不确定如何将 if 函数应用于它?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多