Admin SDK 群組移轉服務

您可以使用 Admin SDK Groups Migration 服務,在 Apps Script 中使用 Admin SDK 的 Groups Migration API。Google Workspace 網域管理員 (包括經銷商) 可透過這個 API,將電子郵件從公用資料夾和發送清單遷移至 Google 網路論壇討論記錄。

參考資料

如要進一步瞭解這項服務,請參閱 Admin SDK Groups Migration API 的參考說明文件。與 Apps Script 中的所有進階服務一樣,Admin SDK 群組遷移服務使用的物件、方法和參數都與公開 API 相同。詳情請參閱「如何判斷方法簽章」。

如要回報問題及尋求其他支援,請參閱「Admin SDK Groups 遷移支援指南」。

程式碼範例

下列程式碼範例使用 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;
}