如何添加" CC"在自动Google电子表格提醒中?

时间:2016-09-08 08:21:35

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

我有一张12列的单张0 1 2 3 4 ----- 12。

值如下。

0 - numbers,
1 - Subject, 
2 - 1st owner mail id, 
3 - 2nd owner mail id, 
4 - Status, 
5 - Date, .... etc.

我写了一些代码,当5 - Date的值被视为最终日期时会自动发送电子邮件。

超过它会根据触发器提供提醒电子邮件/提醒。

代码如下:

function sendEmails() {
  var sheet = SpreadsheetApp
    .getActiveSpreadsheet()
    .getSheetByName("BiWeekly/Monthly Reports");
  var startRow = 2;
  var numRows = sheet.getLastRow();
  var numOfColumns = sheet.getLastColumn();
  var dataRange = sheet.getRange(startRow, 1, numRows, 12);
  var data = dataRange.getValues();

  var status = "";

  var i = 0;
  for (i=0;i<data.length;i++) {
    var row = data[i];
    var emailAddress = row[2];
    var message = row[1];

    status = new Date();

    if (status < status) {
      var subject = "ETA follow up with";
      MailApp.sendEmail(emailAddress, subject, message);
    };
  };
};

问题

如何根据上述条件添加名为CC的功能,该功能应包含第一个所有者邮件ID

2 个答案:

答案 0 :(得分:0)

如果我理解正确(希望!)你只需要这个:

ccEmailAddress = row[3]

MailApp.sendEmail(emailAddress, subject, message, {cc: ccEmailAddress});

有关详细信息,请查看此处的文档 - https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String,Object)

答案 1 :(得分:0)

我刚修改了这段代码的最后一部分。用户正在收到提醒邮件。但是在执行代码时会出现一个错误。它显示无法发送电子邮件:没有收件人(第24行,文件“New_reminders”

function sendEmails() {
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("BiWeekly/Monthly Reports");
  var startRow = 2;
  var numRows = sheet.getLastRow();
  var numOfColumns = sheet.getLastColumn();
  var dataRange = sheet.getRange(startRow, 1, numRows, 12);
  var data = dataRange.getValues();
  var status = "";
  var date = "";
  var i = 0;
  for (i=0;i<data.length;i++) {
  var row = data[i];
  var emailAddress = row[3];
  var emailAddress1 = row[2];
  var message = row[1];
  date = new Date();
  status = row[6];
  if (status < date) {
  var subject = "ETA follow up with";
  MailApp.sendEmail(emailAddress, subject, message, {
  cc: emailAddress1
  });
  };
  };
  };

有没有办法可以100%成功运行代码?