Usługa migracji grup z pakietu Admin SDK

Usługa migracji grup z pakietu Admin SDK umożliwia użycie w Apps Script interfejsu Groups Migration API z pakietu Admin SDK. Ten interfejs API daje administratorom Google Workspace domen (w tym sprzedawcom) możliwość przenoszenia e-maili z folderów publicznych i list dystrybucyjnych do archiwów dyskusji Grup dyskusyjnych Google.

Dokumentacja

Szczegółowe informacje o tej usłudze znajdziesz w dokumentacji interfejsu Groups Migration API z pakietu Admin SDK. Podobnie jak wszystkie zaawansowane usługi w Apps Script usługa migracji grup Admin SDK korzysta z tych samych obiektów, metod i parametrów co publiczny interfejs API. Więcej informacji znajdziesz w artykule Jak określane są podpisy metod.

Aby zgłosić problemy i znaleźć inną pomoc, zapoznaj się z przewodnikiem pomocy na temat migracji grup z pakietu Admin SDK.

Przykładowy kod

Przykładowy kod poniżej wykorzystuje wersję 1 interfejsu API.

Migracja e-maili z Gmaila do grupy dyskusyjnej Google

Ten przykładowy kod pobiera 3 wiadomości w formacie RFC 822 z każdego z 3 ostatnich wątków w skrzynce odbiorczej Gmaila użytkownika, tworzy obiekt blob z treści e-maila (wraz z załącznikami) i wstawia go do grupy dyskusyjnej Google w domenie.

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;
}