【问题标题】:Unable to find a rfc 822 message that works with Google Groups Migration API找不到适用于 Google Groups Migration API 的 rfc 822 消息
【发布时间】:2014-08-14 16:28:49
【问题描述】:

我正在尝试使用 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 接受并愿意分享的消息?还有什么我做错了吗?

感谢任何帮助!

【问题讨论】:

  • 找到一个被 Google 接受的正文:` var body = @"Date: 16 Jul 07 10:12 GMT From: samplesender@example.com To: samplegroup@googlegroups.com Subject: test message Message-Id: 这是已迁移电子邮件的正文。";

标签: c# google-api google-apps google-groups-migration


【解决方案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&gt;

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 谢谢杰!我尝试添加主题和消息 ID,但出现相同的错误 -> 无法解析原始消息 [400]
    • 我找到了解决方案。你走得不远:如果你用&lt;Message-Id: 1234@acme.com&gt; 替换Message-Id: 1234@acme.com 就可以了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2016-07-09
    • 2015-12-12
    • 2011-05-12
    • 1970-01-01
    • 2020-07-19
    • 2010-12-23
    相关资源
    最近更新 更多