Admin SDK 群组迁移服务

通过 Admin SDK 网上论坛迁移服务,您可以在 Apps 脚本中使用 Admin SDK 的 Groups Migration API。此 API 可让网域管理员 Google Workspace (包括转销商)将电子邮件从公共文件夹和分发列表迁移到 Google 网上论坛讨论归档。

参考

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

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

示例代码

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

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

此示例从用户的 Gmail 收件箱中的最新三个会话各获取三条采用 RFC 822 格式的邮件,根据电子邮件内容(包括附件)创建 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;
}