0% found this document useful (0 votes)
67 views

Script Email

This function sends emails based on data from a spreadsheet without sending duplicates. It gets the email addresses and messages from a range of cells, then loops through each row to send an email if the status in the third column does not indicate it has already been sent. After sending, it updates the status column with a constant to prevent future duplicates.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Script Email

This function sends emails based on data from a spreadsheet without sending duplicates. It gets the email addresses and messages from a range of cells, then loops through each row to send an email if the status in the third column does not indicate it has already been sent. After sending, it updates the status column with a constant to prevent future duplicates.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// 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 = 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 (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var emailSent = row[2]; // Third column
if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
var subject = 'Sending emails from a Spreadsheet';
MailApp.sendEmail('[email protected]', 'DMS Service Reminder',
'Sudah saatnya service');
sheet.getRange(startRow + i, 10).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}

You might also like