Last active
July 11, 2021 09:06
-
-
Save Cartmanishere/58130d25975bee9c3acd3c8f03de5aea to your computer and use it in GitHub Desktop.
Email sending example using rendered HTML in appscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renderEmail(context) { | |
var template = HtmlService.createTemplateFromFile("emailTemplate"); | |
template.context = context; | |
return template.evaluate().getContent(); | |
} | |
function sendEmail(order) { | |
var context = { | |
message: "Your order has been accepted! Please find the details as follow:", | |
customerName: order[1], | |
status: order[2], | |
deliveryDate: order[3] | |
} | |
var emailAddress = order[0]; | |
var emailSubject = "Your order has been accepted!"; | |
var emailBody = renderEmail(context); | |
MailApp.sendEmail({ | |
to: emailAddress, | |
subject: emailSubject, | |
htmlBody: emailBody | |
}); | |
} | |
function sendCustomerNotification() { | |
var order = [ | |
"[email protected]", | |
"John Doe", | |
"Accepted", | |
"23 June 2019" | |
]; | |
sendEmail(order); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment