Skip to content Skip to sidebar Skip to footer

Using Email Address From External Html File To Send Email Via Google Apps Script

I'm creating a function within Google Apps whereby I need to email the spreadsheet I am working on as a PDF. The user should click on a button and a dialogue box should open whereb

Solution 1:

1) Define name properties for your inputs. Currently, none of your form fields has the 'name' property. Here's the example of how it should look like

   <inputtype="email" name="email"class="form-control"id="exampleInputEmail1" aria-describedby="emailHelp" value="d.bage@group-miki.com">

This will allow you to access the properties of the form object when the form is submitted (e.g., form.email, form.subject, etc);

2) On the client-side (html), you must write the code to handle the 'submit' event. Add the following before the closing </body> tag:

<script>window.onload = function() {


    document.getElementsByTagName('form')[0]
            .addEventListener('submit', function(e){

              e.preventDefault(); // intercept redirect to another page
              google.script.run.handleFormSubmit(this); // pass the form object to the server-side function. 



            });

 }



 </script>

You can also use jQuery to achieve the same result. Here's my server-side (.gs) function that logs the contents of the input fields

functionhandleFormSubmit(form) {

  Logger.log(form.email);
  Logger.log(form.subject);
  Logger.log(form.message);

}

Use google.script.run for client-server communication. See the docs for more details https://developers.google.com/apps-script/guides/html/communication

Solution 2:

You can send pdf but Google App script does support below extension file .xls and .xlsx in mail service of google API through google app script its only supports pdf and image format attach file go through this link u will get more info regrading this

https://developers.google.com/apps-script/reference/base/blob#getAs(String)

if u still try to attach .xlsx and .xls file it through an error its does not support i already faced this issue but u can download as xlsx format through javascript.

Post a Comment for "Using Email Address From External Html File To Send Email Via Google Apps Script"