Admin SDK 群組移轉服務

Admin SDK 群組遷移服務可讓您在 Apps Script 中使用 Admin SDK 的 Groups Migration API。這個 API 可讓 Google Workspace 網域 (包括經銷商) 的管理員將電子郵件從公用資料夾和通訊群組清單遷移至 Google 網路論壇討論封存資料。

參考資料

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

如要回報問題及尋找其他支援,請參閱 Admin SDK 群組遷移支援指南

程式碼範例

下方程式碼範例使用第 1 版的 API。

將電子郵件從 Gmail 遷移至 Google 網路論壇

這個範例會從使用者 Gmail 收件匣中最新的三個執行緒中,取得三則 RFC 822 格式的訊息,從電子郵件內容 (包括附件) 建立 blob,並將 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;
}