Gmail的API和.NET客户端库:缺少消息草稿[400] [英] Gmail api with .Net CLient library: Missing draft message [400]

查看:170
本文介绍了Gmail的API和.NET客户端库:缺少消息草稿[400]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个使用.NET客户端库在Gmail草稿。我可以成功登录和检索等等认证和API的工作草案的列表。现在我需要创建选秀类的一个实例,并将其发送到API。但什么是草稿邮件需要什么样子的?这不要紧,我填的是API浏览器上的https: //developers.google.com/gmail/api/v1/reference/users/drafts/create ,我的选秀永远是空的。 另外从我的C#code这样做时,我需要设置draft.Message.Raw场到别的我得到一个错误:

 失踪的消息草稿[400]
 

解决方案

使用客户端库,你可以设置的base64 EN codeD邮件给邮件的原始属性,然后使用该消息作为草案的消息属性

更普遍: 消息草案包括ID和信息资源 https://developers.google.com/gmail/api/v1/reference /用户/汇票

  {
  ID:字符串,
  消息:users.messages资源
}
 

该消息资源应该有它的原始字段设置为一个base64 EN codeD RCF 2822格式的字符串。

例如:

 来源:me@email.com
到:you@email.com
主题:测试电子邮件

电子邮件正文
 

为Base64连接codeD字符串是:

<$p$p><$c$c>ZnJvbTogbWVAZW1haWwuY29tDQp0bzogeW91QGVtYWlsLmNvbQ0Kc3ViamVjdDogdGVzdCBlbWFpbA0KDQplbWFpbCBib2R5

因此​​,一个draft.create的请求主体应该是这个样子:

  {
  信息: {
    原始:ZnJvbTogbWVAZW1haWwuY29tDQp0bzogeW91QGVtYWlsLmNvbQ0Kc3ViamVjdDogdGVzdCBlbWFpbA0KDQplbWFpbCBib2R5
  }
}
 

I'm trying to create drafts in Gmail using the .Net Client Library. I can successfully login and retrieve a list of drafts so the authentication and api are working. Now I need to create an instance of the Draft class and send it to the API. But what does the draft message need to look like? It doesn't matter what I fill in the API explorer on https://developers.google.com/gmail/api/v1/reference/users/drafts/create, my draft is always empty. Also when doing it from my C# code I need to set the draft.Message.Raw field to something else I get an error:

Missing draft message [400] 

解决方案

Using the client library you can set the base64 encoded email to the raw property of a Message then use that Message as the message property of the Draft.

More generally: The Draft Message consists of an id and a Message Resource https://developers.google.com/gmail/api/v1/reference/users/drafts

{
  "id": string,
  "message": users.messages Resource
}

The Message Resource should have its "raw" field set to a base64 encoded RCF 2822 formatted string.

Eg:

from: me@email.com
to: you@email.com
subject: test email

email body

As a base64 encoded string is:

ZnJvbTogbWVAZW1haWwuY29tDQp0bzogeW91QGVtYWlsLmNvbQ0Kc3ViamVjdDogdGVzdCBlbWFpbA0KDQplbWFpbCBib2R5

So the request body of a draft.create should look something like:

{
  "message": {
    "raw": "ZnJvbTogbWVAZW1haWwuY29tDQp0bzogeW91QGVtYWlsLmNvbQ0Kc3ViamVjdDogdGVzdCBlbWFpbA0KDQplbWFpbCBib2R5"
  }
}

这篇关于Gmail的API和.NET客户端库:缺少消息草稿[400]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆