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

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

यह एक अडवांस सेवा है. इसका इस्तेमाल करने से पहले, इसे चालू करना ज़रूरी है.

संदर्भ

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

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

नमूना कोड

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

Gmail से किसी Google Group में ईमेल माइग्रेट करना

इस नमूने में, उपयोगकर्ता के Gmail इनबॉक्स में मौजूद, हाल ही के तीन थ्रेड से RFC 822 फ़ॉर्मैट वाले तीन मैसेज लिए जाते हैं. इसके बाद, ईमेल के कॉन्टेंट (अटैचमेंट भी शामिल हैं) से एक ब्लॉब बनाया जाता है. फिर, इसे डोमेन में मौजूद किसी Google Group में जोड़ा जाता है.

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