Creating a Gmail Draft with Recipients through Gmail API

孤人 提交于 2019-12-01 08:29:16

问题


I have been trying to figure out how to automatically add recipients to a Draft email that is created using the Gmail API through their Ruby library. I can create the draft without any issues but setting the recipients is causing me troubles and I haven't been able to find any good examples showing the best way to add email specific things.

Using the Google API playground and pulling in drafts that have already been created, it looks like the structure should be something similar to what is shown below, but whenever the draft is created, there are no recipients.

  @result = client.execute(
    :api_method => gmail.users.drafts.create,
    :parameters => {
      'userId' => "me"      
    },
    :body_object => {
      'message' => {
        'raw' =>  Base64.urlsafe_encode64('Test Email Message'),
        'payload' => {
          'headers' => 
          [
            {
              'name' => "To",
              'value' => "John Smith <john_smith.fake@gmail.com>"
            }
          ]
        }
      }
    }
  )

回答1:


'raw' should contain the entire (RFC822) email, complete with body and headers. Do not use the 'payload.headers' structure, that parsed format is only used for returning during message.get() presently.

so for 'raw' you'd want to Base64.urlsafe_encode64() a string like: "To: someguy@example.com\r\nFrom: myself@example.com\r\nSubject: my subject\r\n\r\nBody goes here"



来源:https://stackoverflow.com/questions/25494664/creating-a-gmail-draft-with-recipients-through-gmail-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!