更改所有者并发送电子邮件

时间:2017-09-21 13:47:51

标签: google-apps-script google-drive-api

好吧,我正在转移几个文件的属性,我想省略通知电子邮件,我在库中找到了一些模型,但如果没有我的代码,我不能这样做,如果有人可以帮助我我'不胜感激

function folderTransfer()
  {
    var pas = DriveApp.getFolderById("ID");
    var arquivos = pas.getFiles();
    var me = 'email'; /* tirar este e-mail e deixar que seja qualquer prop.*/
    var novoProp = 'email';
  
    var pastas = pas.getFolders();
    while (pastas.hasNext())
    {
      var pasta = pastas.next();
      var pastaID = pasta.getId();
      fileTransfer(pastaID, me, novoProp);
      pasta.setOwner(novoProp);
      pasta.removeEditor(me);
    }
    //Transferir pasta pai para novoProp
    pas.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.VIEW);
    pas.setOwner('email');
    pas.removeEditor('email'); 
    
 function fileTransfer(pastaID, prop, novoProp)
  {
    var pasta = DriveApp.getFolderById('id');
    var arquivos = pasta.getFiles();
  
    while (arquivos.hasNext())
    {
      var arquivo = arquivos.next();
      arquivo.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.VIEW);
      arquivo.setOwner('email');
      arquivo.removeEditor('email');
     
      }
    }
 }

1 个答案:

答案 0 :(得分:0)

您正在使用DriveApp打开文件,这会强制通知电子邮件(根据this related question)。如果你知道它是什么类型的文件(doc,sheet等),你应该使用适当的应用程序(SpreadsheetAppDocumentApp等)打开它,以避免发送共享通知。您需要通过相应的应用程序检查要共享的MIME类型。

以下是一些可能更接近的未经测试的代码:

while (arquivos.hasNext())
    {
      var arquivo = arquivos.next();
      var type = arquivo.getMimeType();
      if(type == "application/vnd.google-apps.document") {
        DocumentApp.openById(arquivo.getId()).addEditor('email');
      } else if(type == "application/vnd.google-apps.spreadsheet") {
        SpreadsheetApp.openById(arquivo.getId()).addEditor('email');
      } //etc...
    }

请注意,您只能通过DriveApp设置所有者,这意味着您可以删除电子邮件通知。这是您通过Apps Script获得的最接近的内容。

More in GAS MIME types