Reputation: 73
I can see how to CC particular emails when entered into the g - script. But I want to be able to add multiple users, based on a cell in Sheets, by using a var code to call them.
I've tried adding in a var into the CC syntax to no effect.
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B2
var dataRange = sheet.getRange(startRow, 1, numRows, 3);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var subject = 'ILPA Request';
var body = row[1]; // Second column
var file = DriveApp.getFileById('xxxxxxxxx');
var copy = row[2];
GmailApp.sendEmail(emailAddress, subject, body, {cc: [copy]},
{attachments: [file]});
}
}
I'd like the email to be sent and copy the email addresses in the cell eing referenced, instead I get this error message: Cannot find method sendEmail(string,string,string,object,object). (line 16, file "321").
Upvotes: 2
Views: 105
Reputation: 73
Got it, the below code resolved my issue:
GmailApp.sendEmail(emailAddress, subject, body, {cc: copy, attachments: [file]})
Upvotes: 2