Gmail api with .Net CLient library: Missing draft message [400]

后端 未结 3 1120
面向向阳花
面向向阳花 2021-01-06 09:30

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

3条回答
  •  [愿得一人]
    2021-01-06 10:02

    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"
      }
    }
    

提交回复
热议问题