I've searched everywhere on the web and on this site as well. What I want to do is relatively simple, however I don't know enough about javascript to write it myself but I am learning.
I have a google sheet with email addresses as well as data in 5 columns. Let's say there are 3 email addresses total. Now say there are 3 rows with the same email address and each row has new/different data than the previous row. I want to send JUST 1 email to that address with the 3 rows / 5 columns of data. There also may be an email address but with no data in the rows/columns. Obviously nothing should be sent from that row. Then there's the second email address. Repeat but send to the new email address. Next email, etc.
Here's the sheet to give you a clearer picture. I would like to keep the look/color of the table of column B through Column F in each email.
The following script had me most of the way there (sans the look/color of the table), however when I tried using it a few days ago it was sending a new email for each row of data instead of just one email for several rows of data...but it previously was working! (again sans the look/color of my sheet, it was simple text)
function sendEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheetByName("sheet1"));
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange("A2:m8");
var data = dataRange.getValues();
// Modified
var temp = [];
var emailAddress, data1, data2, data3, data4, data5;
for (var i in data) {
[emailAddress, data1, data2, data3, data4, data5] = data[i];
var message = '\n\n' + data1 + ' ' + data2 + ' ' + data3 + ' ' + data4 + ' ' + data5;
if (emailAddress || !data1) {
if (temp.length > 0) {
MailApp.sendEmail(temp[0], "Subject", temp.slice(1,temp.length).join("\n"));
var temp = [];
}
temp.push(emailAddress, message);
if (!dimension) break;
} else {
temp.push(message);
}
}
}
The format of the body of the email should look like the following, but again, I also want it to retain the look/feel/color from the sheet:
Once that's working, I would like my email signature from Gmail included in the email. I'm not sure if I can get it exactly as is in my Gmail account, or just simple text via javascript.
I have this line but that's simple text. Any way to get my logo/formatting/etc. to match my Gmail or outlook account?
var signature = "\n---\nsample signature";
Your help is much appreciated. Thank you.