我正在尝试使用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部分),它表示我尝试迁移的邮件因格式错误而被拒绝。我尝试了很多不同的消息,但我总是得到同样的错误 - &gt;无法解析原始消息[400]。
是否有人发现Google网上论坛迁移接受并希望分享的消息?还有别的我做错了吗?
感谢任何帮助!
答案 0 :(得分:1)
找到解决方案:
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标头 &LT; NNNN@mail.samplegroup.com>
答案 1 :(得分:0)
尝试添加主题和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.
...