如何确认从Google脚本MailApp.sendEmail发送的电子邮件?

时间:2020-08-18 14:18:11

标签: google-apps-script google-sheets

我有一个电子表格,其中包含每天发送的电子邮件地址和个性化内容的列表。我设置了一个Google Apps脚本来获取数据并发送电子邮件,然后使用基于时间的触发器每天运行它。

我仍然需要为成功发送邮件的每一行返回电子表格(已将current_date设置为 responseCell 值),但我似乎找不到解决方法

这就是我所拥有的,但是我找不到如何为邮件发送过程设置成功处理程序来包装该setValue的方法。我发现的最接近的方法是使用GmailApp函数搜索已发送的文件夹,但是我确定一种更优雅的解决方法。

function sendEmails() {
  var sheet = SpreadsheetApp.getActive().getSheetByName("List of kids");
  // Fetch the range of cells A2:Fmaxrow
  var dataRange = sheet.getRange(2,1,sheet.getMaxRows() -1, 6);
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  var todayis = Utilities.formatDate(new Date(), "GMT+3", "dd/MM/yyyy");
  for (var i in data) {
    var row = data[i];
    var emailAddress = row[2]; // First column
    var message = row[4]; // Third column
    var subject = row[0] + "\'s health declaration for " + todayis;
    MailApp.sendEmail(emailAddress, subject, message);
    var responseCell = sheet.getRange(2+Number(i), 6);
    responseCell.setValue(todayis);
    SpreadsheetApp.flush();
  }
}

0 个答案:

没有答案