Drafts represent unsent messages with the DRAFT
system label applied.
The message contained within the draft cannot be edited once created, but it
can be replaced. In this sense, the
draft resource is simply a container
that provides a stable ID because the underlying message IDs change every time
the message is replaced.
Message resources inside a draft have similar behavior to other messages except for the following differences:
- Draft messages cannot have any label other than the
DRAFT
system label. - When the draft is sent, the draft is automatically deleted and a new message
with an updated ID is created with the
SENT
system label. This message is returned in thedrafts.send
response.
Contents
Creating draft messages
Your application can create drafts using the drafts.create method. The general process is to:
- Create a MIME message that complies with RFC 2822.
- Convert the message to a base64url encoded string.
- Create a draft, setting the
value of the
drafts.message.raw
field to the encoded string.
The following code examples demonstrate the process.
Java
Python
Updating drafts
Similarly to creating a draft, to update a draft you must supply a Draft
resource in the body of your request with the draft.message.raw
field
set to a base64url encoded string containing the MIME message. Because
messages cannot be updated, the message contained in the draft is destroyed
and replaced by the new MIME message supplied in the update request.
You can retrieve the current MIME message contained in the draft by calling
drafts.get
with the parameter
format=raw
.
For more information, see
drafts.update
.
Sending drafts
When sending a draft, you can choose to send the message as-is or as with an
updated message. If you are updating the draft content with a new message,
supply a Draft
resource in the body of the
drafts.send
request; set the
draft.id
of the draft to be sent; and set the draft.message.raw
field to the
new MIME message encoded as a base64url encoded string. For more
information, see drafts.send
.