I'm trying to pass a variable (my name in cell A1) from my code.gs to my Index.html and email it.
Can someone please tell me what I'm doing wrong or point me in the right direction.
Code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('Index');
}
function sendEmail() {
var ss = SpreadsheetApp.openById('MY_SPREADSHEET_ID');
var sheet = ss.getSheetByName('Sheet1');
var myName = sheet.getRange(1,1).getValue();
var template = HtmlService.createTemplateFromFile('Index');
var body = template.evaluate().getContent();
// SEND THE EMAIL
MailApp.sendEmail({
subject:"Test Email",
to:"example@domain.com",
htmlBody: body,
});
return myName;
Index.html
<!DOCTYPE html>
<html>
<body>
<p><? var data = sendEmail(); ?><?= data ?></p>
</body>
</html>