I have a script that sends an email using GmailApp with an html body. I would like the html body to include specific values from the Spreadsheet that contains it, but each time the email is sent, the scriptlet I add is displayed as plain text.
email.gs:
function sendEmail() {
var mailTo = 'example@gmail.com'
var NAME = SpreadsheetApp.getActiveSheet().getRange('Sheet1!A1').getValue();
var subject = 'Hello!'
var html = HtmlService.createHtmlOutputFromFile('body').getContent();
GmailApp.sendEmail('', subject, '', {
name: 'Friend',
htmlBody: html,
bcc: mailTo
});
}
body.html:
<h1>Good Evening, <? NAME ?> </h1>
<h3>Hello Friend!</h3>
"NAME" should be pulled from the specified cell in the sheet whenever the script is run.
I am guessing that the reason it is displaying as text is GmailApp.sendEmail pastes the raw html into the email and assumes the client will read it, so how could I first get it to process through the script and then paste into the email?