使用草稿
「草稿」代表已套用 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
。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-01-15 (世界標準時間)。
[null,null,["上次更新時間: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."]]],[]]