title: How do i allow a CORS requests in my google script?
body: <p>I want to post my contact form to my google script that will send an e-mail to me. I use the following code:</p>
  
  <pre><code>var TO_ADDRESS = "example@gmail.com"; // where to send form data
  
  function doPost(e) {
  
    var callback = e.parameter.callback;
  
    try {
      Logger.log(e); // the Google Script version of console.log
      MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
                        JSON.stringify(e.parameters));
      // return json success results
      return ContentService
            .createTextOutput(callback+
            JSON.stringify({"result":"success",
                            "data": JSON.stringify(e.parameters) }))
            .setMimeType(ContentService.MimeType.JSON);
    } catch(error) { // if error return this
      Logger.log(error);
      return ContentService
            .createTextOutput(callback+JSON.stringify({"result":"error", 
            "error": e}))
            .setMimeType(ContentService.MimeType.JSON);
    }
  }
  </code></pre>
  
  <p>When i try to post to the google script url, i get the following error:</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at
    '<a href="https://script.google.com/macros/s/~~myscriptid~~/exec" rel="noreferrer">https://script.google.com/macros/s/~~myscriptid~~/exec</a>' from origin
    '<a href="http://localhost:4200" rel="noreferrer">http://localhost:4200</a>' has been blocked by CORS policy: Response to
    preflight request doesn't pass access control check: No
    'Access-Control-Allow-Origin' header is present on the requested
    resource.</p>
  </blockquote>
  
  <p>I have no clue how to add the CORS-filter to my google script.</p>
  
  <p>I know the script is working i have tested it with this plugin:</p>
  
  <p><a href="https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi" rel="noreferrer">https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi</a></p>