I am trying to send an email that contains 2 columns of data as the body of the email, and the subject line of the email is comprised of 3 cells in one of the columns (see snippet).
This was my last attempt!!
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 1; // 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);
// 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,2]; // Second column
var subject = 'Here is your BUY DRAFT from Ben's Auto';
MailApp.sendEmail(emailAddress, subject, message);
}
}
I have only been able to get 1 cell to show in the body of an email
If I understood it right from your question and comments:
A1
B1:C15
(2 columns, 15 rows) to the message body In this case, please modify your code as following:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 1;
var numRows = 15; // from your description it seems like you want to append to body the data of all 15 rows
// Fetch the range of cells B1:C15
var dataRange = sheet.getRange(startRow, 2, numRows,2);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
var message='';
var emailAddress = sheet.getRange('A1').getValue();
for (var i=0;i<data.length;i++) {
var row = data[i];
message = message+row[0] + " " + row[1]+'\n';
}
var subject = 'Here is your BUY DRAFT from Ben\'s Auto';
MailApp.sendEmail(emailAddress, subject, message);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.