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 グループの移行サポートガイドをご覧ください。

サンプルコード

以下のサンプルコードでは、API のバージョン 1 を使用しています。

Gmail から Google グループにメールを移行する

このサンプルでは、ユーザーの Gmail 受信トレイにある最新の 3 つのスレッドのそれぞれから RFC 822 形式のメッセージを 3 件取得し、メールのコンテンツ(添付ファイルを含む)から 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;
}