I'm trying to use an HTML template to send custom emails using data collected on a google sheet. I've linked to code to a button so that I select the row/rows I want to email, click the button and it sends to the recipient in that row. I also want the body of the email to contain data from the row. I am using an html body script. I tried to use the same email[column #]
to call data from the sheet in the html script but to no avail. How can I get fields from my sheet to fill the html script in order to send a custom email?
This is the code I'm currently using:
function email() {
var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();
var rng = SpreadsheetApp.getActiveSheet().getActiveRange()
var email = rng.getValues()[0];
MailApp.sendEmail({
to: email[23],
subject: 'Show Seats ' + email[1],
htmlBody: htmlBody,
replyTo:'[email protected]',
});
}
and I have a separate html file also saved in the script. I prefer to keep it in a separate file because it is cleaner for editing.
<html>
<head>
<script>
</script>
</head>
<body>
<p>Hello,</p>
<p> </p>
<p>You are CONFIRMED!</p>
<p>No. of Tickets: email[10]</p>
<p>Date/Time:email[2]</p>
<p>CC Charge: $email[14]</p>
<p>Held Under:email[1]</p>
<p> </p>
<p>Tickets will be held at the Box Office. If you are picking up your tickets in advance, they will be available 48 hours before your selected performance. Please note there is no late seating.</p>
<p> </p>
<p>Thanks!</p>
<div><p><a href="http://www.gap.com/" style="font-family: Tahoma; font-size: 13px;"><img src="https://image.ibb.co/d0aDt6/DEH_Signature_Book.png" /></a></p></div>
</body>
</html>