SHARE
TWEET

Untitled

a guest Jun 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 sendEmails_w_verification() {
  9.   var sheet = SpreadsheetApp.getActiveSheet();
  10.   var startRow = 116; // First row of data to process
  11.   var numColumns = 8;
  12.   var startColumn = 1;
  13.  // Fetch the range of cells as object
  14.   var dataRange = sheet.getRange(startRow, startColumn,
  15. sheet.getLastRow(), numColumns);
  16.   // Fetch values for each row in the Range.
  17.   var data = dataRange.getValues();
  18.   for (var i = 0; i < data.length; ++i) {
  19.     var row = data[i];
  20.     var emailAddress = row[1]; // Second column
  21.     var message = "Thank you for registering for the webinar"; // Second
  22. column
  23.     var emailSent = row[8]; // ninth column
  24.     if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
  25.       var subject = 'AFWERX Webinar Reminder';
  26.       MailApp.sendEmail(emailAddress, subject, message);
  27.       sheet.getRange(startRow + i, 9).setValue(EMAIL_SENT);
  28.      // Make sure the cell is updated right away in case the script is
  29. interrupted
  30.       SpreadsheetApp.flush();
  31.     }
  32.   }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top