Reputation: 71
I'm trying to clean up my code and decided to create a template for the emails rather than having it in the body of the code itself. A simplified version of my code looks like this:
function emailTest() {
var templ = HtmlService.createTemplateFromFile('testSLTMail');
templ.name = "Fazila";
templ.student = "Student1";
templ.oldClass = "classA";
templ.newClass = "classB";
templ.sltName = "Fazila";
templ.changeReason = "testing";
var message = templ.evaluate().getContent();
GmailApp.sendEmail('[email protected]','Test Email', message);
And my HTML template looks like this:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p> Dear <?= sltName ?> </p>
<p> <?= name ?> has requested a change to the following student's timetable: </p>
<p><center><?= student ?>'s timetable from <strong><?= oldClass ?></strong> to <strong><?= newClass ?></strong></center></p>
<p> The reason for this change request is: </p>
<p><center><?= changeReason ?></center></p>
<p> Please confirm this request is authorised below. </p>
<p> Kind regards </p>
<p> Fazila </p>
</body>
</html>
However, when I get the email none of the HTML formatting is going through the email I get looks like this:
<p> Dear Fazila </p> <p> Fazila has requested a change to the following student's timetable: </p> <p><center>Student1's timetable from <strong>classA</strong> to <strong>classB</strong></center></p> <p> The reason for this change request is: </p> <p><center>testing</center></p> <p> Please confirm this request is authorised below. </p> <p> Kind regards </p> <p> Fazila </p>
I'm obviously missing a step somewhere which tells the apps script to apply the HTML formatting but can't see where. Any ideas?
Thanks
Upvotes: 1
Views: 267
Reputation: 389
Use this Email constructor :
MailApp.sendEmail({
to: "[email protected]",
subject: "test",
htmlBody: message
});
It works!
Upvotes: 2
Reputation: 3847
consider using htmlBody
option:
GmailApp.sendEmail('[email protected]','Test Email', { htmlBody: message });
documented here
Upvotes: 1