एडमिन SDK टूल के ग्रुप को माइग्रेट करने की सेवा

Admin SDK की ग्रुप माइग्रेशन सेवा की मदद से, Apps Script में Admin SDK के Groups Migration API का इस्तेमाल किया जा सकता है. इस एपीआई की मदद से, डोमेन के एडमिन (इसमें रीसेलर भी शामिल हैं) को, सार्वजनिक फ़ोल्डर और डिस्ट्रिब्यूशन सूचियों से ईमेल को Google Groups के चर्चा के संग्रह में माइग्रेट करने की सुविधा मिलती है.

रेफ़रंस

इस सेवा के बारे में ज़्यादा जानकारी के लिए, Admin SDK Groups Migration API का रेफ़रंस दस्तावेज़ देखें. Apps Script की सभी बेहतर सेवाओं की तरह ही, Admin SDK ग्रुप माइग्रेशन सेवा, सार्वजनिक एपीआई के जैसे ही ऑब्जेक्ट, तरीकों, और पैरामीटर का इस्तेमाल करती है. ज़्यादा जानकारी के लिए, मेथड सिग्नेचर तय करने का तरीका लेख पढ़ें.

समस्याओं की शिकायत करने और अन्य सहायता पाने के लिए, एडमिन SDK ग्रुप माइग्रेशन की सहायता गाइड देखें.

नमूना कोड

यहां दिए गए सैंपल कोड में, एपीआई के वर्शन 1 का इस्तेमाल किया गया है.

Gmail से Google ग्रुप में ईमेल माइग्रेट करना

इस सैंपल में, उपयोगकर्ता के Gmail इनबॉक्स में मौजूद तीन सबसे नई थ्रेड में से हर थ्रेड के तीन RFC 822 फ़ॉर्मैट वाले मैसेज मिलते हैं. साथ ही, ईमेल कॉन्टेंट (जिसमें अटैचमेंट भी शामिल हैं) से एक ब्लॉब बनाया जाता है और उसे डोमेन के 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;
}