Greetings to all my learned friends. I am trying to send mails from my google spread sheet through google scripting. The following is the script. The script is executing successfully. The mails are not sent.
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
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 Email = row[0]; // First column
var Subject = row[1] // Second column;
var Message = row[2]; // Third column
file = DriveApp.getFilesByName('Marks.xls');function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
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 Email = row[0]; // First column
var Subject = row[1] // Second column;
var Message = row[2]; // Third column
file = DriveApp.getFilesByName('Marks.xls');
file2 = DriveApp.getFilesByName('Remuneration.pdf');
if (file.hasNext() && file2.hasNext()) {
MailApp.sendEmail(Email, Subject, Message, {
attachments: [
file.next().getAs('application/msexcel'),
file2.next().getAs('application/pdf')],
name: 'Automatic Emailer Script'}
)
}
}
}
file2 = DriveApp.getFilesByName('Remuneration.pdf');
if (file.hasNext() && file2.hasNext()) {
MailApp.sendEmail(Email, Subject, Message, {
attachments: [
file.next().getAs('application/msexcel'),
file2.next().getAs('application/pdf')],
name: 'Automatic Emailer Script'}
)
}
}
}
Can somebody help?