onedit为什么不能发送电子邮件? [英] onedit why cannot send email?

查看:102
本文介绍了onedit为什么不能发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的脚本,应该在单元格发生变化时发送电子邮件。

  function onEdit(e){

var doc = e.source;

var r = doc.getActiveRange()。getValue();


if(r ==Niccolò){
var a = doc.getActiveRange()。setBackground('#ff0000');
var b = GmailApp.sendEmail('name@gmail.com','subject','body');






$ b

此功能也会改变单元格的颜色。
问题是单元格的颜色有效,所以它不会发送任何电子邮件。
这看起来很简单,我不明白为什么不行!

解决方案

简单的触发器像 onEdit() onOpen()或 onFormSubmit()可能的操作集合,因为它们未经授权运行,请参阅文档以获取更多详细信息。



因此,您描述的这种行为是正常的。



您应该使用可安装的触发器,而不是像在同一文档页面。

这里是对文档的总结:

这些简单的触发器响应动作在Google Spreadsheets中,它们以活动用户身份运行。例如,如果Bob打开电子表格,那么onOpen函数将作为Bob运行,而不管谁将脚本添加到电子表格。由于这个原因,简单的触发器被限制在允许的范围内:
当Spreadsheet以只读模式打开时,它们不能执行。
他们无法确定当前用户。
他们无法访问任何需要以该用户身份进行身份验证的服务。例如,Google翻译服务是匿名的,可以通过简单的触发器访问。 Google日历,Gmail和网站不是匿名的,简单的触发器无法访问这些服务。
他们只能修改当前的电子表格。禁止访问其他电子表格。
有关事件权限的更多信息,请参阅从容器特定触发器执行。


i've this simple script that should send an email when a cell is changed

function onEdit(e) {  

var doc = e.source; 

 var r = doc.getActiveRange().getValue();


 if (r == "Niccolò"){
var a = doc.getActiveRange().setBackground('#ff0000');
var b = GmailApp.sendEmail('name@gmail.com', 'subject', 'body');

}

}

This function change also cell colour. THe problem is that the cell colour works, so it's change while doesn't send any email. It looks so simple i don't understand why doesn't works!

解决方案

Simple triggers like onEdit(), onOpen() or onFormSubmit() have a limited set of possible actions because they run without authorization , see the documentation for further details.

So this behavior you describe is normal.

You should use an installable trigger instead as explained in the same doc page.

here is an summary of the documentation :

These simple triggers run in response to actions in Google Spreadsheets, and they run as the active user. For example, if Bob opens the Spreadsheet, then the onOpen function runs as Bob, irrespective of who added the script to the Spreadsheet. For this reason, the simple triggers are restricted in what they are permitted to do: They cannot execute when the Spreadsheet is opened in read-only mode. They cannot determine the current user. They cannot access any services that require authentication as that user. For example, the Google Translate service is anonymous and can be accessed by the simple triggers. Google Calendar, Gmail, and Sites are not anonymous and the simple triggers cannot access those services. They can only modify the current Spreadsheet. Access to other Spreadsheets is forbidden. For more information on event permissions, see Executing from a Container-Specific Trigger.

这篇关于onedit为什么不能发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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