【问题标题】:Adding message to email when using addEditor()使用 addEditor() 时向电子邮件添加消息
【发布时间】:2022-01-20 02:35:21
【问题描述】:

在 Apps Script 中,我目前正在以编程方式生成文件,通过 addEditor() 添加用户并自动向他们发送电子邮件。

我现在想做的是扩展它以包含一条消息。我认为这与这个绿色框相对应:

我在这里也发现了一个类似的问题,但一直无法正常工作:How to send a custom message when adding a viewer to Google Spreadsheet via Google Apps Scripts?

这是我目前所拥有的:

  setPermission(documentId, email) {

    // Get the document to set permissions on
    const file = DriveApp.getFileById(documentId);

    // Turn off sharing by editors
    file.setShareableByEditors(false);

    // Add the email to editors
    file.addEditor(email);

  }  

如果我尝试做类似的事情:

...
file.addEditor(email, {emailMessage: 'Test'});

我收到以下错误:

Exception: The parameters (String,(class)) don't match the method signature for DriveApp.File.addEditor.

所以我很好奇:

  1. 这可行吗?
  2. 语法需要是什么?

【问题讨论】:

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


    【解决方案1】:

    作为documentedfile.addEditor() 只有一个参数:电子邮件地址(或User 对象)。因此无法通过该方法添加电子邮件。

    但是,您可以使用Advanced Drive Service 完成此操作。 首先,您需要enable Advanced Drive Service。

    然后使用这样的东西(reference):

    Drive.Permissions.insert(
      {
        'role': 'writer,
        'type': 'user',
        'value': email // the email address you wish to share with
      },
      documentId, // id of the file you want to share
      {
        'sendNotificationEmails': 'true',
        'emailMessage': message // The message you want to send, as a plain text string
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-03
      相关资源
      最近更新 更多