Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This constant is written in column C for rows for which an email
- // has been sent successfully.
- var EMAIL_SENT = 'EMAIL_SENT';
- /**
- * Sends non-duplicate emails with data from the current spreadsheet.
- */
- function sendEmails2() {
- var sheet = SpreadsheetApp.getActiveSheet();
- var startRow = 2; // First row of data to process
- var numRows = 3; // Number of rows to process Change to last line of DATA minus 1
- // Fetch the range of cells A2:N4 Change to last line of DATA minus 1
- var dataRange = sheet.getRange(startRow, 1, numRows, 3);
- // Fetch values for each row in the Range.
- //The Next line is added to try to find the pdf
- var file = DriveApp.getFilesByName('2019 05 18 Update.pdf')
- var data = dataRange.getValues();
- for (var i = 0; i < data.length; ++i) {
- var row = data[i];
- var emailAddress = row[0]; // Fifth column
- var message = row[1]; // Third column change heading to message (orlink to)
- var emailSent = row[2]; // Columnn C
- if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
- var subject = 'Update from your HOA';
- //The next line is added to link the pdf to the email
- // MailApp.sendEmail(emailAddress, subject, message, {attachments: file});
- // THIS REMOVED AND REPLACED WITH THE NEXT LINE MailApp.sendEmail(emailAddress, subject, message);
- MailApp.sendEmail(emailAddress, subject, message,
- {attachments: file.next().getBlob()} )
- sheet.getRange(startRow + i, 3).setValue(EMAIL_SENT);
- // Make sure the cell is updated right away in case the script is interrupted
- SpreadsheetApp.flush();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement