Gmail API的messages.send方法中电子邮件正文的大小限制是多少?

时间:2015-07-02 14:31:50

标签: gmail-api

我使用官方.net api client通过messages.send方法发送带附件的电子邮件。当我附上一个大小超过5mb的文件时,我来

[JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.]
   Newtonsoft.Json.JsonTextReader.ParseValue() +1187
   Newtonsoft.Json.JsonTextReader.ReadInternal() +65
   Newtonsoft.Json.JsonTextReader.Read() +28
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter) +237
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) +783
   Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) +293
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) +274
   Newtonsoft.Json.JsonConvert.DeserializeObject(String value, JsonSerializerSettings settings) +57
   Google.Apis.Json.NewtonsoftJsonSerializer.Deserialize(String input) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis.Core\Apis\Json\NewtonsoftJsonSerializer.cs:120
   Google.Apis.Services.<DeserializeError>d__8.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:286

[GoogleApiException: An Error occurred, but the error response could not be deserialized]
   Google.Apis.Requests.ClientServiceRequest`1.Execute() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Requests\ClientServiceRequest.cs:102

我认为客户使用Metadata URI, for metadata-only requests。我将尝试另一种选择:上传URI,用于媒体上传请求。 看起来电子邮件大小有限制导致客户端库中的解析错误响应异常。

所以,第一个问题:是否有尺寸限制? 其次,没有关于如何通过客户端使用different upload methods的信息,你知道任何客户端库文档吗?

更新:我攻击了

生成的请求
var request = gmailService.Users.Messages.Send(message, AccountUserId);

将转到https://www.googleapis.com/gmail/v1/users/me/messages/send。因为我认为它没有使用媒体上传请求。

4 个答案:

答案 0 :(得分:1)

我最终限制了附件总大小。这是代码段。

班级:

public const int MaxAttachmentsSize = 5 * 1024 * 1024;

方法级别:

var attachmentsSize = 0;
foreach (var attachment in attachments)
{
    attachmentsSize += attachment.Item1;
    if (attachmentsSize > MaxAttachmentsSize) break;
    mailMessage.Attachments.Add(attachment.Item2);
}

答案 1 :(得分:0)

整个消息的MB有限制。谷歌API允许您使用相当大的电子邮件,但如果您的服务由于连接速度太长而发送,则可能会在发送时超时。

根据这篇谷歌文档,这是35MB:

google api send docs

答案 2 :(得分:0)

对于任何(上传)超过几MB的内容,您一定要使用该方法的/ upload版本,否则您可能会遇到这些大小限制。

答案 3 :(得分:0)

回答你问题的第二部分......

  

其次,没有关于如何通过客户端使用不同上传方法的信息,您知道任何客户端库文档吗?

我在API中做了一些讨论,我发现还有一种方法将流作为第三个参数。

services.Users.Messages.Send( body, userId, stream, contentType)

深入了解其源代码,我发现它似乎使用了一个类似于以下内容的网址:

upload/....

我还没有尝试过,而且我还不知道它想要什么“流”,但这看起来很有可能获得更大限制的可恢复上传。