简体   繁体   English

来自网页的 Google Apps 脚本 GmailApp

[英]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我正在尝试使用 Angular 5 访问 Google Apps Script Gmail 服务。这是一个简单的发送电子邮件功能

My GAS code is as follows:我的 GAS 代码如下:

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.然后我将其发布为访问 Web 应用程序和任何人的用户。

I get no error in Stackdriver Logging.我在 Stackdriver Logging 中没有发现错误。 I simply get a CORS error on the local console which to me historically means an error elsewhere.我只是在本地控制台上收到 CORS 错误,这对我来说在历史上意味着其他地方的错误。

Any thoughts or ideas is appreciated.任何想法或想法表示赞赏。 Thank you.谢谢你。

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.由于我没有足够的声誉来发表评论并要求提供更多信息,因为您的回答是在 2018 年提出的,您可能已经修补了它,我将在下面列出。

Getting a CORS error has a few reasons which for you, which could be:收到 CORS 错误有几个原因,可能是:

  1. 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.如果您的脚本未返回任何内容,则 google 脚本将提供一个 HTML 页面,说明该代码未返回任何内容,这将触发 CORS 错误。
  2. Your script has encountered an error, which will also cause google script to return a HTML page and also cause a CORS error.您的脚本遇到了错误,这也会导致 google 脚本返回 HTML 页面,还会导致 CORS 错误。

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.您可以使用hurl.it测试它以查看您的脚本返回的内容,您可以在 google 脚本编辑器中测试您的脚本并将其设置为可能的值。

Hope this is not too late!希望这还不算太晚!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM