Google REST API - RFC 2822 格式和 base64url 编码字符串中的消息 [英] Google REST API - message in an RFC 2822 formatted and base64url encoded string

查看:32
本文介绍了Google REST API - RFC 2822 格式和 base64url 编码字符串中的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 - 试试看Google REST API - Users.messages: send .

有一个必需的参数 - raw -

<块引用>

采用 RFC 2822 格式和 base64url 编码字符串的整个电子邮件消息.在messages.get 和drafts.get 响应中返回时提供了 format=RAW 参数.

我检查了 RFC 2822 格式,似乎它应该显示为 sample here ,然后我用这个编码器将 base64URL 编码并将其粘贴到 尝试 我得到 - 字节字符串的无效值:http://ostermiller.org/calc/encode.html .

你能给我提供一个正确的 RFC 2822 格式 及其对应的 base64URL,它可以在上面的 试试 ?

解决方案

示例邮件可能如下所示:

发件人:sender@gmail.com至:receiver@gmail.com主题:主题文本消息文本在这里

在您的浏览器中打开开发者工具并对其进行 Base64 编码并将所有 + 替换为 -,将所有 / 替换为 _,并删除尾随的 = 以使其 URL 安全:

btoa("发件人:sender@gmail.com\r\n" +"收件人:receiver@gmail.com\r\n" +"主题:主题文本\r\n\r\n" +消息文本在这里").replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');

这将为您提供以下数据:

RnJvbTogc2VuZGVyQGdtYWlsLmNvbQ0KVG86IHJlY2VpdmVyQGdtYWlsLmNvbQ0KU3ViamVjdDogU3ViamVjdCBUZXh0DQoNClRoZHlWlXZIHpZYpdZXIHJlY2VpdmVyQGdtYWlsLmNvbQ0KU3ViamVjdDogU3ViamVjdXI

使用上述字符串作为 API Explorer 发送邮件.

I try the use the - try it of Google REST API - Users.messages: send .

There is there a required parameter - raw -

The entire email message in an RFC 2822 formatted and base64url encoded string. Returned in messages.get and drafts.get responses when the format=RAW parameter is supplied.

I checked about RFC 2822 format and seems it should displayed as the sample here , then I encoded it the base64URL with this encoder and paste it the raw field of the try it and I get - Invalid value for ByteString: http://ostermiller.org/calc/encode.html .

Can you provide me a correct RFC 2822 format and its corresponding base64URL which it would work in the above try it ?

解决方案

An example mail could look like this:

From: sender@gmail.com
To: receiver@gmail.com
Subject: Subject Text

The message text goes here

Open up the Developer Tools in your browser and Base64 encode it and replace all + with -, replace all / with _, and remove the trailing = to make it URL-safe:

btoa(
  "From: sender@gmail.com\r\n" +
  "To: receiver@gmail.com\r\n" +
  "Subject: Subject Text\r\n\r\n" +

  "The message text goes here"
).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');

This will give you the following data:

RnJvbTogc2VuZGVyQGdtYWlsLmNvbQ0KVG86IHJlY2VpdmVyQGdtYWlsLmNvbQ0KU3ViamVjdDogU3ViamVjdCBUZXh0DQoNClRoZSBtZXNzYWdlIHRleHQgZ29lcyBoZXJl

Use this string above as your raw-parameter in the API Explorer to send the mail.

这篇关于Google REST API - RFC 2822 格式和 base64url 编码字符串中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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