Google Apps Script - Sending Google Spreadsheet Row to Email

Posted by AME on Stack Overflow See other posts from Stack Overflow or by AME
Published on 2010-03-28T03:37:02Z Indexed on 2010/03/28 3:43 UTC
Read the original article Hit count: 759

Hi I am trying to write a script using Google Apps Script (Javascript) for a Google spreadsheet.

I am trying to do the same thing that is shown in this tutorial [http://www.google.com/google-d-s/scripts/sending_emails.html][1], but each row in my spreadsheet has 24 columns.

I would like to send out the contents of each row as an email. Here is the code as I am trying to use:

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var dataRange = sheet.getRange("A2:X31")
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (i in data) {
    var row = data[i];
    var i = i + 1; 
    var emailAddress = row[0];  // First column
    var message = row[1];       // Second column
    var subject = "Sending emails from a Spreadsheet";
    MailApp.sendEmail(emailAddress, subject, message);
  }
}?

The result is an email with the contents in the "B" column only. Can someone help me change this code to get all of the contents in each row (columns A-X).

Thanks,

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-spreadsheet