Admin SDK Groups Migration Service

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 G Suite domains (including resellers) the ability to migrate emails from public folders and distribution lists to Google Groups discussion archives.


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.

Sample code

The sample code below uses version 1 of the API.

Migrate emails from Gmail to a Google Group

This sample 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() {
  var groupId = '';
  var messagesToMigrate = getRecentMessagesContent();
  for (var i = 0; i < messagesToMigrate.length; i++) {
    var messageContent = messagesToMigrate[i];
    var 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() {
  var NUM_THREADS = 3;
  var NUM_MESSAGES = 3;
  var threads = GmailApp.getInboxThreads(0, NUM_THREADS);
  var messages = GmailApp.getMessagesForThreads(threads);
  var messagesContent = [];
  for (var i = 0; i < messages.length; i++) {
    for (var j = 0; j < NUM_MESSAGES; j++) {
      var message = messages[i][j];
      if (message) {
  return messagesContent;


Apps Script
Apps Script