Skip to content

Instantly share code, notes, and snippets.

@pastcompute
Created April 17, 2016 11:42
Show Gist options
  • Save pastcompute/69f69cd80e705d79fc363154552f110b to your computer and use it in GitHub Desktop.
Save pastcompute/69f69cd80e705d79fc363154552f110b to your computer and use it in GitHub Desktop.
Google sheets email merge
function sendEmails() {
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, 2) // r, c, NR, NC
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var subject = "Sending emails from a Spreadsheet";
MailApp.sendEmail(emailAddress, subject, message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment