1

我正在尝试使用 C# Google Groups Migration API,但运气不佳。

我有以下代码:

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

我不断收到以下异常:

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]
]

根据 Groups Migration API 文档(https://developers.google.com/admin-sdk/groups-migration/v1/reference/archive/insert参见页面底部的 responseCode 部分),它表明消息我正在尝试迁移被拒绝为格式错误。我尝试了许多不同的消息,但总是收到相同的错误 -> 无法解析原始消息 [400]。

有没有人发现 Google Groups Migration 接受并愿意分享的消息?还有什么我做错了吗?

任何帮助感激不尽!

4

2 回答 2

2

找到解决方案:

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

底线,如果您希望 Google 接受您的消息,您必须使用以下格式放置 Message-id 标头<NNNN@mail.samplegroup.com>

于 2014-08-27T13:06:40.713 回答
0

尝试添加主题和消息 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.

...
于 2014-08-14T20:21:38.850 回答