1

I'm trying to use the C# Google Groups Migration API and not having much luck.

I have the following code:

var body =
@"Date: 16 Jul 07 10:12 GMT
From: samplesender@example.com
To: samplegroup@googlegroups.com


This is the body of the migrated email message.


";

var bytes = ASCIIEncoding.ASCII.GetBytes(body);

var messageStream = new MemoryStream(bytes);

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets { ClientId = "<insert client id here>", ClientSecret = "<insert client secret here>" },
    new[] { "https://www.googleapis.com/auth/apps.groups.migration" },
    "user",
    CancellationToken.None,
    new FileDataStore("GroupsMigration.Auth.Store")).Result;

var service = new GroupsMigrationService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "group migration application"
});

var request = service.Archive.Insert("<insert valid group email here>", messageStream, "message/rfc822");

IUploadProgress uploadStatus = request.Upload();

if (uploadStatus.Exception != null)
{
    Console.WriteLine(uploadStatus.Exception.ToString());
}

I keep getting the following exception :

The service groupsmigration has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError
Unable to parse the raw message [400]
Errors [
   Message[Unable to parse the raw message] Location[ - ] Reason[invalid] Domain[global]
]

According to the Groups Migration API documentation (https://developers.google.com/admin-sdk/groups-migration/v1/reference/archive/insert see the responseCode section towards the bottom of the page), it indicates that the message I am trying to migrate is rejected as malformed. I tried many different messages and I always get the same error -> Unable to parse the raw message [400].

Did anybody find a message that the Google Groups Migration accepts and would like to share ? Anything else I am doing wrong ?

Any help gratefully appreciated!

  • Found a body that is accepted by Google : ` var body = @"Date: 16 Jul 07 10:12 GMT From: samplesender@example.com To: samplegroup@googlegroups.com Subject: test message Message-Id: <1234@acme.com> This is the body of the migrated email message. "; –  Aug 27 '14 at 12:53

2 Answers2

2

Found the solution :

var body =
@"Date: 16 Jul 07 10:12 GMT
From: samplesender@example.com
To: samplegroup@googlegroups.com
Message-Id: <12345@acme.com>


This is the body of the migrated email message.


";

var bytes = ASCIIEncoding.ASCII.GetBytes(body);

var messageStream = new MemoryStream(bytes);

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    new ClientSecrets { ClientId = "<insert client id here>", ClientSecret = "<insert client secret here>" },
    new[] { "https://www.googleapis.com/auth/apps.groups.migration" },
    "user",
    CancellationToken.None,
    new FileDataStore("GroupsMigration.Auth.Store")).Result;
        
var service = new GroupsMigrationService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "group migration application"
});

var request = service.Archive.Insert("<insert valid group email here>", messageStream, "message/rfc822");

IUploadProgress uploadStatus = request.Upload();

if (uploadStatus.Exception != null)
{
    Console.WriteLine(uploadStatus.Exception.ToString());
}

Bottom line, if you want Google to accept your message you must put a Message-id header with the following format <NNNN@mail.samplegroup.com>

Jerther
  • 5,558
  • 8
  • 40
  • 59
0

Try adding a subject and message-id:

var body =
@"Date: 16 Jul 07 10:12 GMT
From: samplesender@example.com
To: samplegroup@googlegroups.com
Subject: test message
Message-Id: 1234@acme.com

This is the body of the migrated email message.

...
Jay Lee
  • 13,415
  • 3
  • 28
  • 59
  • Thanks Jay! I tried adding a subject and message-id but I am getting the same error -> Unable to parse the raw message [400] –  Aug 27 '14 at 12:47
  • 1
    I found the solution. You were not far : if you replace `Message-Id: 1234@acme.com` by `` it works. –  Aug 27 '14 at 12:57