I created a script that helps me send bulk HTML emails to multiple recipients. In my Google Sheet file Col 1 contains the email address and Col 2 has the Name of the recipient. The one more thing i am trying to achieve and got stuck at is that i want to populate each email with the name of the recipient. For example , i am sending email to [email protected] , i would like the email to start with "Dear xxx" and so on for all recipients.
How can this be done?
My code is as follows:
function sendEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var lc = ss.getLastColumn();
for (var i = 2;i<=lr;i++){
var currentEmail = ss.getRange(i, 1).getValue();
var subjectLine = "Test";
var htmlOutput = HtmlService.createHtmlOutputFromFile('email');
var email = htmlOutput.getContent();
MailApp.sendEmail( currentEmail, "test", email, { htmlBody: email } )
}
}
Thank you