Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  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 = 3; // Number of rows to process Change to last line of DATA minus 1
  12. // Fetch the range of cells A2:N4 Change to last line of DATA minus 1
  13. var dataRange = sheet.getRange(startRow, 1, numRows, 3);
  14. // Fetch values for each row in the Range.
  15. //The Next line is added to try to find the pdf
  16. var file = DriveApp.getFilesByName('2019 05 18 Update.pdf')
  17. var data = dataRange.getValues();
  18. for (var i = 0; i < data.length; ++i) {
  19. var row = data[i];
  20. var emailAddress = row[0]; // Fifth column
  21. var message = row[1]; // Third column change heading to message (orlink to)
  22. var emailSent = row[2]; // Columnn C
  23. if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
  24. var subject = 'Update from your HOA';
  25. //The next line is added to link the pdf to the email
  26. // MailApp.sendEmail(emailAddress, subject, message, {attachments: file});
  27. // THIS REMOVED AND REPLACED WITH THE NEXT LINE MailApp.sendEmail(emailAddress, subject, message);
  28. MailApp.sendEmail(emailAddress, subject, message,
  29. {attachments: file.next().getBlob()} )
  30. sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);
  31. // Make sure the cell is updated right away in case the script is interrupted
  32. SpreadsheetApp.flush();
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement