'Google Apps Script GmailApp from Web Page
I am trying to access Google Apps Script Gmail service with Angular 5. This is a simple Send an Email function
My GAS code is as follows:
function doGet(e){
var addressee = e.parameters.addressee;
var subject = e. parameters.subject;
var body = e.parameters.body;
sendEmailNA(addressee, subject, body);
}
function sendEmailNA(addressee, subject, body) {
GmailApp.sendEmail(addressee, subject, body);
}
My Angular Service:
sendGoogleEmailNoAttach(addressee: string, subject: string, body: string){
return this.http.get('https://script.google.com/macros/s/[script ID here]/exec?addressee='+addressee+'&subject='+subject+'&body='+body);
}
My Angular Component:
sendGoogleEmail(){
for(var i = 0; i < this.addressees.length; i++){
this.dataService.sendGoogleEmailNoAttach(this.addressees[i].email, this.message.subject, this.message.body)
.subscribe((data: any) =>{
console.log(data);
this.addressees = [];
this.message.attachments = [];
})
}
}
I then publish it as User accessing the web app and Anyone.
I get no error in Stackdriver Logging. I simply get a CORS error on the local console which to me historically means an error elsewhere.
Any thoughts or ideas is appreciated. Thank you.
Solution 1:[1]
There are a few possible problems that can be happening here. As I do not have enough reputation to comment and ask for more information, as your answer was asked in 2018 and you might have patched it, I will list it down below.
Getting a CORS error has a few reasons which for you, which could be:
- Your script ran and returned nothing, though it is unclear whether you have patched it. If your script returned nothing, google script will serve a HTML page saying that the code returned nothing which will trigger a CORS error.
- Your script has encountered an error, which will also cause google script to return a HTML page and also cause a CORS error.
You can test it using hurl.it to see what your script returns, and you can test your script inside the google script editor and set it to possible values.
Hope this is not too late!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ansel Lee |
