Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
365 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...