Stay organized with collections
Save and categorize content based on your preferences.
The Admin SDK Groups Migration service allows you to use the Admin SDK's
Groups Migration API in Apps Script. This
API gives administrators of Google Workspace domains
(including resellers) the
ability to migrate emails from public folders and distribution lists to
Google Groups discussion archives.
Reference
For detailed information on this service, see the
reference documentation
for the Admin SDK Groups Migration API. Like all advanced services in Apps
Script, the Admin SDK Groups Migration service uses the same objects, methods,
and parameters as the public API. For more information, see How method signatures are determined.
This sample gets three RFC 822 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.
/** * 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. */functionmigrateMessages(){// TODO (developer) - Replace groupId value with yoursconstgroupId='exampleGroup@example.com';constmessagesToMigrate=getRecentMessagesContent();for(constmessageContentofmessagesToMigrate){constcontentBlob=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. */functiongetRecentMessagesContent(){constNUM_THREADS=3;constNUM_MESSAGES=3;constthreads=GmailApp.getInboxThreads(0,NUM_THREADS);constmessages=GmailApp.getMessagesForThreads(threads);constmessagesContent=[];for(leti=0;i < messages.length;i++){for(letj=0;j < NUM_MESSAGES;j++){constmessage=messages[i][j];if(message){messagesContent.push(message.getRawContent());}}}returnmessagesContent;}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-18 UTC."],[[["\u003cp\u003eThe Admin SDK Groups Migration service enables administrators to migrate emails from public folders and distribution lists to Google Groups using Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires prior enabling in Google Workspace domains (including resellers) before use.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can leverage the Admin SDK Groups Migration API to programmatically manage email migration workflows.\u003c/p\u003e\n"],["\u003cp\u003eSample code provided demonstrates how to migrate RFC 822 formatted emails from Gmail to a designated Google Group.\u003c/p\u003e\n"],["\u003cp\u003eComprehensive documentation and support resources are available to guide developers in utilizing the service effectively.\u003c/p\u003e\n"]]],[],null,["The Admin SDK Groups Migration service allows you to use the Admin SDK's\n[Groups Migration API](/admin-sdk/groups-migration) in Apps Script. This\nAPI gives administrators of Google Workspace domains\n(including resellers) the\nability to migrate emails from public folders and distribution lists to\nGoogle Groups discussion archives.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n\nFor detailed information on this service, see the\n[reference documentation](/admin-sdk/groups-migration/v1/reference)\nfor the Admin SDK Groups Migration API. Like all advanced services in Apps\nScript, the Admin SDK Groups Migration service uses the same objects, methods,\nand parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Admin SDK Groups Migration support guide](/admin-sdk/groups-migration/support).\n\nSample code\n\nThe sample code below uses [version 1](/admin-sdk/groups-migration/v1/reference)\nof the API.\n\nMigrate emails from Gmail to a Google Group\n\nThis sample gets three RFC 822 formatted messages from the each of the latest\nthree threads in the user's Gmail inbox, creates a blob from the email content\n(including attachments), and inserts it in a Google Group in the domain. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```gosu\n/**\n * Gets three RFC822 formatted messages from the each of the latest three\n * threads in the user's Gmail inbox, creates a blob from the email content\n * (including attachments), and inserts it in a Google Group in the domain.\n */\nfunction migrateMessages() {\n // TODO (developer) - Replace groupId value with yours\n const groupId = 'exampleGroup@example.com';\n const messagesToMigrate = getRecentMessagesContent();\n for (const messageContent of messagesToMigrate) {\n const contentBlob = Utilities.newBlob(messageContent, 'message/rfc822');\n AdminGroupsMigration.Archive.insert(groupId, contentBlob);\n }\n}\n\n/**\n * Gets a list of recent messages' content from the user's Gmail account.\n * By default, fetches 3 messages from the latest 3 threads.\n *\n * @return {Array} the messages' content.\n */\nfunction getRecentMessagesContent() {\n const NUM_THREADS = 3;\n const NUM_MESSAGES = 3;\n const threads = GmailApp.getInboxThreads(0, NUM_THREADS);\n const messages = GmailApp.getMessagesForThreads(threads);\n const messagesContent = [];\n for (let i = 0; i \u003c messages.length; i++) {\n for (let j = 0; j \u003c NUM_MESSAGES; j++) {\n const message = messages[i][j];\n if (message) {\n messagesContent.push(message.getRawContent());\n }\n }\n }\n return messagesContent;\n}\n```"]]