Skip to content

Instantly share code, notes, and snippets.

@promediacorp
Last active June 23, 2017 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save promediacorp/e94a5e4cb80b65ec461ea317635b26dd to your computer and use it in GitHub Desktop.
Save promediacorp/e94a5e4cb80b65ec461ea317635b26dd to your computer and use it in GitHub Desktop.
email from google sheet script
// https://developers.google.com/apps-script/articles/sending_emails
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails() {
var body = DocumentApp.openById('1BHx9yBH9zTo27w35B2iSwXzHfn1UWS_KOAIo2OEugsE'); //this is the google doc id for the email body
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 25; // 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 fullName = row[0];
var emailAddress = row[1]; // First column
var message = body; // Second column
var emailSent = row[4]; // Third column
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "Please Add An Event Apart to your UX Event List"; //subject body
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 5).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment