I'am very new in gas. The scenario is this : Having a spreadsheet with the list of recipient and their names, I want to automate and customize the body of the email writing on the top "Dear {name}". How can I pass the variable into the Htmlbody option?
Here is part of the code... Thanks in advance.
var ss = SpreadsheetApp.openById("xxxxxxxxxxxxxxxxxxxx").getSheets()[0];
var rng = ss.getRange(2, 1, ss.getLastRow()-1, 8);
var rngvls = rng.getValues();
//
for (var i = 0 ; i<rngvls.length; i++){
var name= ss.getRange(i + 2, 5, 1, 1).getValue();
GmailApp.sendEmail(dest, ogg, body,{name:nam, attachments: [fail.getAs(MimeType.PDF)], htmlBody : <html><h1>here is the header</h1> and here the name
</html>});
The values are already in rngvls. Using the method getValue() in a loop isn't very good for performance.
You can add the name to a string containing the html using concatenation.
Try this: