Home > OS >  The output for "createHtmlOutputFromFile" is very literal and not utilizing the code I wro
The output for "createHtmlOutputFromFile" is very literal and not utilizing the code I wro

Time:04-28

So I wrote a script that has an HTML file associated with it. The script is long so I won't post it, but at the end I have this:

  // Send HTML content in email

  var htmlBody = HtmlService.createHtmlOutputFromFile("AttendanceInfractionsHTMLTemplate").getContent();

  MailApp.sendEmail({
    to: Session.getActiveUser().getEmail(),
    subject: 'EI Email',
    htmlBody: htmlBody,
  });
}

The problem is that when I receive the email in my inbox, the code in the HTML template hasn't run successfully and it shows the scriptlets in all their glory, such as my if/else statements and all that. This doesn't happen when I deploy a test of the HTML file. Any ideas? Can't seem to find anything about this in the Google Apps Script reference guide.

CodePudding user response:

You need to use createTemplateFromFile() and evaluate() it:

var htmlBody = HtmlService.createTemplateFromFile("AttendanceInfractionsHTMLTemplate")
  .evaluate()
  .getContent()
  • Related