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

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

问题描述

我一直在尝试弄清楚如何将收件人自动添加到使用 Gmail API 通过他们的 Ruby 库创建的草稿电子邮件中.我可以毫无问题地创建草稿,但设置收件人给我带来了麻烦,我无法找到任何好的示例来展示添加电子邮件特定内容的最佳方式.

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 Playground 并拉入已经创建的草稿,看起来结构应该类似于下面显示的内容,但无论何时创建草稿,都没有收件人.

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.

所以对于原始",您需要 Base64.urlsafe_encode64() 一个字符串,例如:"收件人:someguy@example.com 发件人:myself@example.com 主题:我的主题 正文在这里"

so for 'raw' you'd want to Base64.urlsafe_encode64() a string like: "To: someguy@example.com From: myself@example.com Subject: my subject Body goes here"

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

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