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会收到文件共享的电子邮件.
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);
我想共享所有自动电子邮件,因为在该过程结束时,如果该过程成功完成,我将发送自定义电子邮件(文件夹链接中的文件),否则,我将删除该文件夹. 我能怎么做? DocList将很快被弃用!!
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!!
推荐答案
为此,您需要使用驱动器API权限.插入方法 [注意,它不是DriveApp]静默插入权限.
To do this you'll need to use the Drive API permissions.insert method [notice it's not DriveApp] to silently insert a permission.
驱动器API 通过 Google云端硬盘高级服务.要使用它,您需要为您的项目启用它.
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.
这篇关于addViewer与DriveApp类一起使用的方法始终将电子邮件发送给收件人.我可以禁用电子邮件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!