使用草稿
“草稿”表示已应用 DRAFT
系统标签的未发送邮件。草稿中包含的消息一经创建便无法修改,但可以替换。从这个意义上讲,草稿资源只是提供稳定 ID 的容器,因为每当消息被替换时,底层消息 ID 都会发生变化。
草稿中的消息资源的行为与其他消息类似,但存在以下差异:
- 草稿邮件不得带有
DRAFT
系统标签以外的任何标签。
- 草稿发送后,系统会自动删除草稿,并使用
SENT
系统标签创建一个具有更新 ID 的新消息。此消息会在 drafts.send
响应中返回。
目录
创建草稿邮件
您的应用可以使用 drafts.create 方法创建草稿。一般流程如下:
- 创建符合 RFC 2822 的 MIME 邮件。
- 将消息转换为 base64url 编码的字符串。
- 创建草稿,将
drafts.message.raw
字段的值设置为编码字符串。
以下代码示例演示了此过程。
更新草稿
与创建草稿类似,如需更新草稿,您必须在请求正文中提供 Draft
资源,并将 draft.message.raw
字段设置为包含 MIME 邮件的 base64url 编码字符串。由于无法更新邮件,草稿中包含的邮件会被销毁,并替换为更新请求中提供的新 MIME 邮件。
您可以通过使用参数 format=raw
调用 drafts.get
来检索草稿中包含的当前 MIME 邮件。
如需了解详情,请参阅 drafts.update
。
发送草稿
发送草稿时,您可以选择按原样发送邮件,也可以发送更新后的邮件。如果您要使用新邮件更新草稿内容,请在 drafts.send
请求的正文中提供 Draft
资源;设置要发送的草稿的 draft.id
;并将 draft.message.raw
字段设置为编码为 base64url 编码字符串的新 MIME 邮件。如需了解详情,请参阅 drafts.send
。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-01-15。
[null,null,["最后更新时间 (UTC):2025-01-15。"],[[["Drafts are unsent messages identified by the `DRAFT` system label, acting as containers with stable IDs while their underlying message IDs can change upon replacement."],["Draft messages can only have the `DRAFT` system label and are automatically deleted and replaced with a new `SENT` message upon sending."],["Creating a draft involves constructing a MIME message, encoding it in base64url, and then using the `drafts.create` method to create the draft with the encoded message."],["Updating a draft requires replacing the entire message content by providing a new base64url encoded MIME message in the `drafts.update` request."],["Sending a draft can be done as-is or with updated content using the `drafts.send` method, which allows for providing a new MIME message in the request body."]]],[]]