Admin SDK 群组迁移服务

通过 Admin SDK 群组迁移服务,您可以使用 Admin SDK 的 Apps 脚本中的 Groups Migration API。这个 通过 API,管理员可以 Google Workspace 为网域 (包括转销商) 能够将公共文件夹和通讯组列表中的电子邮件迁移到 Google 群组讨论归档。

参考

有关此服务的详细信息,请参阅 参考文档 (适用于 Admin SDK Groups Migration API)。与应用中的所有高级服务一样 Admin SDK 群组迁移服务使用相同的对象、方法和脚本, 和参数作为公共 API。如需了解详情,请参阅如何确定方法签名

如需报告问题和寻求其他支持,请参阅 Admin SDK 群组迁移支持指南

示例代码

以下示例代码使用的是版本 1 该 API 的高级 API。

将电子邮件从 Gmail 迁移到 Google 群组

此示例从每一封最新的 在用户的 Gmail 收件箱中创建三个会话,然后根据电子邮件内容创建 Blob (包括附件),然后将其插入网域内的某个 Google 群组中。

advanced/adminSDK.gs
/**
 * Gets three RFC822 formatted messages from the each of the latest three
 * threads in the user's Gmail inbox, creates a blob from the email content
 * (including attachments), and inserts it in a Google Group in the domain.
 */
function migrateMessages() {
  // TODO (developer) - Replace groupId value with yours
  const groupId = 'exampleGroup@example.com';
  const messagesToMigrate = getRecentMessagesContent();
  for (const messageContent of messagesToMigrate) {
    const contentBlob = Utilities.newBlob(messageContent, 'message/rfc822');
    AdminGroupsMigration.Archive.insert(groupId, contentBlob);
  }
}

/**
 * Gets a list of recent messages' content from the user's Gmail account.
 * By default, fetches 3 messages from the latest 3 threads.
 *
 * @return {Array} the messages' content.
 */
function getRecentMessagesContent() {
  const NUM_THREADS = 3;
  const NUM_MESSAGES = 3;
  const threads = GmailApp.getInboxThreads(0, NUM_THREADS);
  const messages = GmailApp.getMessagesForThreads(threads);
  const messagesContent = [];
  for (let i = 0; i < messages.length; i++) {
    for (let j = 0; j < NUM_MESSAGES; j++) {
      const message = messages[i][j];
      if (message) {
        messagesContent.push(message.getRawContent());
      }
    }
  }
  return messagesContent;
}