我想通过 Javascript/Google 应用程序脚本中的 API 响应向用户发送电子邮件?

I want to send email to user from API response in Javascript/ Google App Script?

我正在使用 google 应用程序脚本从外部 API 获取数据。我想知道是否有一种方法可以在执行以下代码后将 JSON 中的数据发送到 G-suite/Gmail 上的用户电子邮件。有人知道如何做到这一点吗?

  var url = 'https....';
  var response = UrlFetchApp.fetch(url, options);
  if (response.getResponseCode() === 200) {
  var json = JSON.parse(response);
  var id = json["id"];
  sheet.getRange(2+i, 21).setValue(id);
  sheet.getRange(2+i, 22).setValue(1);
  }
else {
 sheet.getRange(2+i, 22).setValue(2);

您可以使用这两个 sendEmail 函数之一,具体取决于您是希望 json 简单地位于正文 [1] 中还是作为附件 [2]。一个简单的例子是:

GmailApp.sendEmail("mike@example.com", "current time", "The time is:");

[1] https://developers.google.com/apps-script/reference/gmail/gmail-app#sendemailrecipient,-subject,-body

[2] https://developers.google.com/apps-script/reference/gmail/gmail-app#sendemailrecipient,-subject,-body,-options