Skip to content Skip to sidebar Skip to footer

Apps Script: How To Email Google Sheet File To Email Specified In Html Service Input?

I am working to build in an HTML Service UI within my Google Sheets file that allows the user to key in the target recipient email address inside the pop-up dialog box within the H

Solution 1:

You can't call a server-side function from the client directly. You need to use the google.script.run API to communicate between the two. Try the following:

// Inside your Apps Script .gs code

// listen for an object sent from the HTML form
function sendEmail(formObj) {

  // Extract the email address submitted
  var to = formObj.email;

  // Send the email
  MailApp.sendEmail(to,"good morning", "The email body")
}
...
<body>
  <form id="emailForm">
      <p>Send to Email Address:</p>
      <br> 
      <input type="email" id="emailInput" name="email" size="40"/> <!-- "name" becomes the key in formObject -->
      <br>
      <input type="button" value="Send Email" onclick="google.script.run.sendEmail(this.parentNode)" /> <!-- google.script.run allows you to call server-side functions -->
      </form>
</body>
...

Post a Comment for "Apps Script: How To Email Google Sheet File To Email Specified In Html Service Input?"