通过Gmail API与收件人创建Gmail草稿 [英] Creating a Gmail Draft with Recipients through Gmail API

查看:153
本文介绍了通过Gmail API与收件人创建Gmail草稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出如何自动将收件人添加到通过其Ruby库使用Gmail API创建的草稿电子邮件。我可以在没有任何问题的情况下创建草稿,但是设置收件人会给我带来麻烦,而且我还找不到任何可以添加特定电子邮件的最佳方式的示例。

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.

使用Google API操作平台并提取已创建的草稿,结构看起来应该与以下所示类似,但是在草稿创建时,不会有收件人。

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


推荐答案

'raw'应该包含完整的(RFC822)电子邮件,包含正文和标题。不要使用'payload.headers'结构,解析后的格式仅用于在message.get()目前返回。

'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.

因此对于'raw'想要Base64.urlsafe_encode64()这样的字符串:
To:someguy@example.com\r\\\
From:myself@example.com\r\\\
Subject:my subject \r\\\
\r \\\
Body去这里

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"

这篇关于通过Gmail API与收件人创建Gmail草稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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