addViewer与DriveApp类一起使用的方法始终将电子邮件发送给收件人。(addViewer the method used with the class DriveApp always se

编程入门 行业动态 更新时间:2024-10-11 05:23:25
addViewer与DriveApp类一起使用的方法始终将电子邮件发送给收件人。(addViewer the method used with the class DriveApp always sends the email to the recipient. Can I disable the email?)

代码A和B执行相同的操作但是在添加查看器时的情况A中,命令addViewer不会将电子邮件发送到currentUser。 相反,在添加查看器的情况B中,currentUser接收文件共享的电子邮件。

//CASE A var f = DocsList.getFolderById(folder.getId()); f.addViewer(currentUser); //CASE B var f = DriveApp.getFolderById(folder.getId()); f.addViewer(currentUser);

我想分享wihouth自动电子邮件,因为在程序结束时我将发送一个自定义电子邮件(文件夹内的文件链接)如果程序成功完成,其他我将删除该文件夹。 我能怎么做? DocList很快就会被弃用!!

Code A and B do the same things but in case A when add a viewer, the command addViewer don't send the email to currentUser. Instead, in the case B when add a viewer the currentUser receive an email of file sharing.

//CASE A var f = DocsList.getFolderById(folder.getId()); f.addViewer(currentUser); //CASE B var f = DriveApp.getFolderById(folder.getId()); f.addViewer(currentUser);

I would like to share wihouth automatic email because at the end of procedure I'll send a custom email (with the file inside folder link) if the procedure completed successfull, otherwaise I will delete the folder. How can I do? DocList will soon be deprecated!!

最满意答案

为此,您需要使用Drive API permissions.insert方法 [注意它不是DriveApp]以静默方式插入权限。

Drive API通过Google云端硬盘高级服务向Google Apps脚本展示。 要使用它,您需要为项目启用它 。

完成后,您的权限插入代码可能如下所示:

/** * Insert a new permission without sending notification email. * * @param {String} fileId ID of the file to insert permission for. * @param {String} value User or group e-mail address, domain name or * {@code null} "default" type. * @param {String} type The value "user", "group", "domain" or "default". * @param {String} role The value "owner", "writer" or "reader". */ function insertSilentPermission(fileId, value, type, role) { var request = Drive.Permissions.insert({ 'value': value, 'type': type, 'role': role, 'withLink': false }, fileId, { 'sendNotificationEmails': false }); }

我编辑了这个答案,将Laura的反馈包括在内,所以它现在按预期工作。

To do this you'll need to use the Drive API permissions.insert method [notice it's not DriveApp] to silently insert a permission.

The Drive API is exposed to Google Apps Script through the Google Drive Advanced Service. To use it you'll need to enable it for your project.

Once that's done your permission insert code might look like this:

/** * Insert a new permission without sending notification email. * * @param {String} fileId ID of the file to insert permission for. * @param {String} value User or group e-mail address, domain name or * {@code null} "default" type. * @param {String} type The value "user", "group", "domain" or "default". * @param {String} role The value "owner", "writer" or "reader". */ function insertSilentPermission(fileId, value, type, role) { var request = Drive.Permissions.insert({ 'value': value, 'type': type, 'role': role, 'withLink': false }, fileId, { 'sendNotificationEmails': false }); }

I've edited this answer to include Laura's feedback below so it now works as expected.

更多推荐

本文发布于:2023-07-14 19:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收件人   发送给   电子邮件   方法   DriveApp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!