在Google AppMaker中发送电子邮件时出错

时间:2018-05-23 04:46:21

标签: javascript gmail-api google-app-maker

我想在用户点击按钮时发送电子邮件通知。该按钮将调用arrayVal = [{ sources: { data: [{ id: 1 }] } }, { sources: { data: [{ id: 2 }] } } ] let result = arrayVal.map((x) => x.sources.data[0].id) console.log(result)函数并调用客户端脚本,如下所示:

sendEmail(widget)

然后它将传递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)

但是当我点击按钮时,我得到了以下错误。有什么帮助吗?

enter image description here

2 个答案:

答案 0 :(得分:1)

看起来您的邮件正文需要在HTML正文中转换,

这是样本

function sendEmails(item){  

  var to = item.OwnerEmail;

  var subject = 'Please Review';

  var body = 'hello<br/>my name is Muhammad Alif bin Azali'; 
  var template = HtmlService.createTemplate(body);
  var htmlBody = template.evaluate().getContent();


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

答案 1 :(得分:1)

不幸的是,您无法将您想要的任何内容作为参数传递给服务器功能。与服务器的通信有一些limitations

  

...大多数类型都是合法的,但不是日期,功能或DOM元素......

     

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

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

有不同的策略来处理这个限制,其中一个是将记录的键作为函数的参数传递。

// 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);
  ...
}