在Google AppMaker中发送电子邮件时出错 [英] Error in sending Email in Google AppMaker

查看:58
本文介绍了在Google AppMaker中发送电子邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户单击按钮时发送电子邮件通知.该按钮将调用sendEmail(widget)函数并调用客户端脚本,如下所示:

I want to send an email notification whenever the user clicks on a button. The button will call sendEmail(widget) function and invoke a client script as follow:

function sendEmail(widget){

  var item = widget.datasource.item;

  google.script.run
    .withFailureHandler(function(error) {
      console.text = error.message;
    })
   .withSuccessHandler(function(result) {
      console.text = 'succeed';
   })
 .sendEmails(item);
}

然后它将通过item传递数据源,并从服务器脚本中调用sendEmails(item)函数,如下所示:

then it will pass the datasource on item and call sendEmails(item) function from a server script as follows:

function sendEmails(item){  

  var to = item.OwnerEmail;

  var subject = 'Please Review';

  var body = 'hello<br/>my name is Muhammad Alif bin Azali';

  MailApp.sendEmail({
      to: to,
      subject: subject,
      htmlBody: body,
      noReply: true
  });
}

但是当我单击按钮时,出现了以下错误.有帮助吗?

but when I click the button I got following error instead. Any help?

推荐答案

不幸的是,您无法将所需的任何参数作为参数传递给服务器函数.与服务器的通信具有一些局限性:

Unfortunately, you cannot pass whatever you want as a parameter to your server function. Communication to the server has some limitations:

...大多数类型是合法的,但不是Date,Function或DOM元素...

...most types are legal, but not Date, Function, or DOM element...

...创建循环引用的对象也会失败...

...objects that create circular references will also fail...

App Maker的记录肯定违反了这些限制.

App Maker's records definitely violate those restrictions.

有多种处理此限制的策略,其中一种是将记录的键作为函数的参数传递.

There are different strategies to handle this limitation, one of them is passing record's key as function's parameter.

// Client script
function sendEmail(widget) {
  var item = widget.datasource.item;

  google.script.run
  ...
 .sendEmails(item._key);
}

// Server script
function sendEmails(itemKey) {
  var item = app.models.MyModel.getRecord(itemKey);
  ...
}

这篇关于在Google AppMaker中发送电子邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆