little_code
little_code

Reputation: 216

How to add "CC" in the automatic Google spreadsheet reminder?

I am having a sheet which is having 12 columns as 0 1 2 3 4 ----- 12.

The values are as follows.

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

I wrote some code which is automatically sending Emails when the value at 5 - Date is considered as final date.

On exceeding it will give reminder emails/reminder as per the trigger.

The code is as follows:

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);
    };
  };
};

Question

How can I add a function, named CC, which should contain the 1st owner mail id, as per the above condition.

Upvotes: 0

Views: 1635

Answers (2)

little_code
little_code

Reputation: 216

I just modified in the last part of this code. The users are getting the reminder mails. But One error is showing at the time of executing the code. It is showing Failed to send email: no recipient (line 24, file "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
  });
  };
  };
  };

Is there any way that I can run the code in 100% success?

Upvotes: 0

Julien C
Julien C

Reputation: 230

If I understood correctly (hopefully!) you just need this:

ccEmailAddress = row[3]

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

For more information check the documentation here - https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String,Object)

Upvotes: 1

Related Questions