Creating draft via Google Gmail API

后端 未结 2 1037
谎友^
谎友^ 2020-12-04 03:39

I am trying to create a draft message for a logged in user but keep getting the error Missing draft message when I run the below

require \'googl         


        
相关标签:
2条回答
  • 2020-12-04 04:13

    I had the same issue when I was trying to do this for the first time as well. The solution that I found was to not include the message information as part of the parameters, but rather pass that on in the :body_object as shown below.

    @result = client.execute(
      :api_method => gmail.users.drafts.create,
      :parameters => {
        'userId' => "me"      
      },
      :body_object => {
        'message' => {
          'raw' =>  Base64.urlsafe_encode64('Test Email Message')
        }
      }
    )
    
    0 讨论(0)
  • 2020-12-04 04:25

    raw in message is the full SMTP message.

    • Either you set the content in body_object
    • Or you set the full SMTP message including headers in message

    eg:

    params = { 'userId' => 'me', 'draft' => { 'message' => {'raw' => 'From: foo@example.com\nSubject:Ignore\n\ntest email' } } }
    
    0 讨论(0)
提交回复
热议问题