Layanan Migrasi Grup Admin SDK

Dengan layanan Migrasi Grup Admin SDK, Anda dapat menggunakan Groups Migration API Admin SDK di Apps Script. API ini memberi administrator Google Workspace domain (termasuk reseller) kemampuan untuk memigrasikan email dari folder publik dan daftar distribusi ke arsip diskusi Google Grup.

Referensi

Untuk mendapatkan informasi mendetail tentang layanan ini, lihat dokumentasi referensi untuk Admin SDK Groups Migration API. Seperti semua layanan lanjutan di Apps Script, layanan Migrasi Grup Admin SDK menggunakan objek, metode, dan parameter yang sama seperti API publik. Untuk informasi selengkapnya, lihat Cara tanda tangan metode ditentukan.

Untuk melaporkan masalah dan menemukan dukungan lainnya, lihat Panduan dukungan Migrasi Grup Admin SDK.

Kode contoh

Kode contoh di bawah ini menggunakan API versi 1.

Memigrasikan email dari Gmail ke Google Grup

Contoh ini mendapatkan tiga pesan berformat RFC 822 dari masing-masing dari tiga thread terbaru di kotak masuk Gmail pengguna, membuat blob dari konten email (termasuk lampiran), dan menyisipkannya ke dalam Google Grup di domain.

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