Search code examples
javascripthtmlgoogle-apps-scripthtml-email

MailApp Google Script Html Template Script


I designed an HTML body that is send, using MailApp.sendEmail method, when the function is called. The HTML contains a button that link the email with a file that search in the run moment. Inside the html file I'm trying to run a JS script to change the button reference. I tried in different ways but I couldn't run any kind of script with this Code.gs call.

Code.gs

var htmlBody = HtmlService.createHtmlOutputFromFile("index.html").getContent();

email.html

<button id="linkButton" href="">
   Descargar
</button>

<script>
   var link = document.getElementById("linkButton");
   link.href = "https://www.url.com";
</script>

I wonder if there's another way to run the script inside the HTML email body or if there's another way to call the index.html from the Code.gs where the scripts could be executed. I know that is a simple question but I didn't find any information about how this could be solved.


Solution

  • You are missing that some email clients doesn't allow messages that include JavaScript so avoid the use of JavaScript.

    Related