使用者在 Gmail 帳戶中建立的草稿郵件。
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
delete | void | 刪除這封草稿郵件。 |
get | String | 取得這封草稿郵件的 ID。 |
get | Gmail | 傳回代表這封草稿的 GmailMessage。 |
get | String | 傳回代表這項草稿的 Gmail ID。 |
send() | Gmail | 傳送這封草稿電子郵件訊息。 |
update(recipient, subject, body) | Gmail | 取代這封草稿郵件的內容。 |
update(recipient, subject, body, options) | Gmail | 使用選用引數替換這封草稿郵件的內容。 |
內容詳盡的說明文件
deleteDraft()
刪除這封草稿郵件。
const draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder draft.deleteDraft(); draft.getMessage(); // Throws exception.
授權
使用這個方法的指令碼需要透過下列一或多個範圍或相關 REST API 中的適當範圍授權:
-
https://mail.google.com/
getId()
取得這封草稿郵件的 ID。
const draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder const draftId = draft.getId(); const draftById = GmailApp.getDraft(draftId); Logger.log( draft.getMessage().getSubject() === draftById.getMessage().getSubject(), );
回攻員
String:草稿 ID
授權
使用這個方法的指令碼需要透過下列一或多個範圍或相關 REST API 中的適當範圍授權:
-
https://mail.google.com/
getMessage()
傳回代表這封草稿的 GmailMessage。
const draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder const message = draft.getMessage(); Logger.log(message.getSubject());
回攻員
GmailMessage:代表這份草稿內容的訊息
授權
使用這個方法的指令碼需要透過下列一或多個範圍或相關 REST API 中的適當範圍授權:
-
https://mail.google.com/
getMessageId()
傳回代表這項草稿的 GmailMessage ID。
const draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder const messageId = draft.getMessageId(); Logger.log(messageId === draft.getMessage().getId());
回攻員
String:郵件 ID
授權
使用這個方法的指令碼需要透過下列一或多個範圍或相關 REST API 中的適當範圍授權:
-
https://mail.google.com/
send()
傳送這封草稿電子郵件訊息。電子郵件大小 (包括標頭) 超出配額限制。
const draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder const msg = draft.send(); // Send it Logger.log(msg.getDate()); // Should be approximately the current timestamp
回攻員
GmailMessage:新傳送的訊息
授權
使用這個方法的指令碼需要透過下列一或多個範圍或相關 REST API 中的適當範圍授權:
-
https://mail.google.com/
update(recipient, subject, body)
取代這封草稿郵件的內容。電子郵件大小 (包括標頭) 超出配額限制。
// The code below will update a draft email with the current date and time. const draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder const now = new Date(); draft.update( 'mike@example.com', 'current time', `The time is: ${now.toString()}`, );
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
recipient | String | 以半形逗號分隔的電子郵件地址清單 |
subject | String | 電子郵件主旨 (最多 250 個半形字元) |
body | String | 電子郵件內文 |
回攻員
GmailDraft:最新更新的草稿
授權
使用這個方法的指令碼需要透過下列一或多個範圍或相關 REST API 中的適當範圍授權:
-
https://mail.google.com/
另請參閱
update(recipient, subject, body, options)
使用選用引數替換這封草稿郵件的內容。電子郵件可以包含純文字或 HTML 內文。電子郵件大小 (包括標頭) 超出配額限制。
// Update a draft email with a file from Google Drive attached as a PDF. const draft = GmailApp.getDrafts()[0]; // The first draft message in the drafts folder const file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); draft.update( 'mike@example.com', 'Attachment example', 'Please see attached file.', { attachments: [file.getAs(MimeType.PDF)], name: 'Automatic Emailer Script', }, );
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
recipient | String | 以半形逗號分隔的電子郵件地址清單 |
subject | String | 電子郵件主旨 (最多 250 個半形字元) |
body | String | 電子郵件內文 |
options | Object | 指定進階參數的 JavaScript 物件,如下所列 |
進階參數
| 名稱 | 類型 | 說明 |
|---|---|---|
attachments | Blob | 要隨電子郵件傳送的檔案陣列 |
bcc | String | 以逗號分隔的密件副本電子郵件地址清單 |
cc | String | 以逗號分隔的副本收件者電子郵件地址清單 |
from | String | 電子郵件的寄件者地址,必須是 Gmail 傳回的其中一個值 |
html | String | 如果已設定,能夠算繪 HTML 的裝置會使用這個引數,而非必要的主體引數;如果電子郵件有內嵌圖片,您可以在 HTML 主體中加入選用的 inline 欄位 |
inline | Object | JavaScript 物件,包含從圖片鍵 (String) 到圖片資料 (Blob) 的對應;這假設使用 html 參數,且該參數包含格式為 <img src="cid:imageKey" /> 的圖片參照 |
name | String | 電子郵件寄件者的名稱 (預設為使用者名稱) |
reply | String | 做為預設回覆地址的電子郵件地址 (預設值:使用者的電子郵件地址) |
回攻員
GmailDraft:最新更新的草稿
授權
使用這個方法的指令碼需要透過下列一或多個範圍或相關 REST API 中的適當範圍授權:
-
https://mail.google.com/