Reputation: 79
I'm trying to send an email using a html template created in the script editor. This is my code:
var template = HtmlService.createTemplateFromFile('emailTemplate');
// get some data from a Spreadsheet and format them in a html table (function getTable below)
var idCodes = idSheet.getSheets()[0].getRange(1, 1, numOfStudents, 2).getValues();
var idCodesTable = getTable(idCodes);
// set the template var
template.teacherName = teacher;
template.formUrl = formPublicUrl;
template.idCodes = idCodesTable;
var emailSubject = 'Questionario di autovalutazione delle competenze digitali (classe ' + classroom + section + ')';
var emailBody = template.evaluate().getContent();
// Send the email
MailApp.sendEmail({
to: teacherMail,
subject: emailSubject,
htmlBody: emailBody,
});
}
function getTable(data) {
var result = [];
var ll = data[0].length;
var row = 0;
for(var i = 0, l = data.length; i < l; i++) {
row = data[i];
result.push("<tr>");
for(var ii = 0; ii < ll; ii++){
result.push('<td>' + row[ii] + '</td>');
}
result.push("</tr>");
}
return result.join('\n');
}
The email arrives, the html in the template is shown correctly but not the table (html tag are visible as you can see in the screenshot).
What am I doing wrong?
This is the file I use to generate the template:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h2>Il questionario per la tua classe è pronto!</h2>
<p>Gentile <?= teacherName ?>,</p>
<p>il questionario per i tuoi studenti è pronto e disponibile a questo indirizzo:</p>
<p><?= formUrl ?></p>
<p>Condividi con loro questo collegamento e assegna a ciascun studente uno dei seguenti codici identificativi:</p>
<table><tr><th>N.</th><th>Codice</th></tr><?= idCodes ?></table>
<p>Ricordati quali codici hai associato ai tuoi studenti (un buon metodo potrebbe essere assegnare i codici in base al numero dello studente in elenco di classe). Riceverai un report delle risposte dopo che <strong>tutti</strong> i tuoi studenti avranno risposto al questionario</p>
<p>Per assistenza puoi scrivere all'indirizzo INSERISCI MAIL DI ASSISTENZA</p>
</body>
</html>
I tried to write all the table tags in the getTable function but that doesn't change a thing, everything that comes out from that function is not parsed in the email even though the html code is correct. Thank you for any help you can give.
Screenshot of the generated email
All html table tag generated by the funcione getTable (no headers)
Upvotes: 0
Views: 471
Reputation: 79
I have found the solution using force-printing scriplets in the html document, like this:
<table><tr><th>N.</th><th>Codice</th></tr><**?!=** idCodes ?></table>
Upvotes: 2