Using google.script.run within the HTML body of an email

40 views
Skip to first unread message

Anas Raiss

unread,
Jun 12, 2023, 7:37:10 AM6/12/23
to Google Apps Script Community
Hi all,

I would like to send an email which contains a link / button in the HTML email body. Once the recipient clicked on the link / button, I would like to run a server-side function on Google Apps Script.

Somehow, I can't get this to work (the logs in the function runFuncServer never show up). Can you please share if you see any issue with the below code? Or if I should be addressing this problem through another approach?

Many thanks for the help
Anas

Here is my Code.gs:
function launchTest() {
var htmlStringService = HtmlService.createHtmlOutputFromFile("EmailBody");
GmailApp.sendEmail("random...@gmail.com", "Title", 'Body not used', { htmlBody: htmlStringService.getContent()});
}

function runFuncServer() {
console.info('Server function was called correctly!');
}

Here is EmailBody.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<script>
function runFuncClient(){
google.script.run.runFuncServer();
}
</script>
<body>
This is a simple email. Please click <button onclick='runFuncClient()'>here</button>
</body>
</html>
Reply all
Reply to author
Forward
0 new messages