Gmail Service
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Gmail
這項服務可讓您傳送電子郵件、撰寫草稿、管理標籤、標記郵件和郵件串,以及執行各種其他 Gmail 帳戶管理工作。另請參閱郵件服務,這項服務較為簡單,僅允許傳送電子郵件。
類別
方法
方法 | 傳回類型 | 簡短說明 |
createDraft(recipient, subject, body) | GmailDraft | 建立電子郵件草稿。 |
createDraft(recipient, subject, body, options) | GmailDraft | 建立草擬電子郵件訊息,並可選擇性地提供引數。 |
createLabel(name) | GmailLabel | 建立指定名稱的新使用者標籤。 |
deleteLabel(label) | GmailApp | 刪除指定標籤。 |
getAliases() | String[] | 取得在 Gmail 中設為這個帳戶別名的電子郵件清單。 |
getDraft(draftId) | GmailDraft | 依 ID 擷取電子郵件草稿。 |
getDraftMessages() | GmailMessage[] | 擷取所有郵件草稿。 |
getDrafts() | GmailDraft[] | 取得所有 Gmail 郵件草稿。 |
getInboxThreads() | GmailThread[] | 不論標籤為何,都會擷取所有收件匣討論串。 |
getInboxThreads(start, max) | GmailThread[] | 擷取一系列收件匣討論串,不論標籤為何。 |
getInboxUnreadCount() | Integer | 取得收件匣中未讀討論串的數量。 |
getMessageById(id) | GmailMessage | 依 ID 取得郵件。 |
getMessagesForThread(thread) | GmailMessage[] | 擷取指定討論串中的所有訊息。 |
getMessagesForThreads(threads) | GmailMessage[][] | 擷取指定討論串中的所有訊息。 |
getPriorityInboxThreads() | GmailThread[] | 擷取所有優先收件匣郵件串,不論標籤為何。 |
getPriorityInboxThreads(start, max) | GmailThread[] | 擷取優先收件匣中的一系列郵件串,不論標籤為何。 |
getPriorityInboxUnreadCount() | Integer | 取得優先收件匣中未讀討論串的數量。 |
getSpamThreads() | GmailThread[] | 擷取所有垃圾內容討論串,不論標籤為何。 |
getSpamThreads(start, max) | GmailThread[] | 擷取一系列垃圾內容討論串,不論標籤為何。 |
getSpamUnreadCount() | Integer | 取得未讀垃圾郵件討論串的數量。 |
getStarredThreads() | GmailThread[] | 擷取所有已加星號的郵件串,不論標籤為何。 |
getStarredThreads(start, max) | GmailThread[] | 擷取已加星號的郵件串,不論標籤為何。 |
getStarredUnreadCount() | Integer | 取得已加星號的未讀討論串數量。 |
getThreadById(id) | GmailThread | 依 ID 取得執行緒。 |
getTrashThreads() | GmailThread[] | 擷取所有垃圾桶中的郵件串,不論標籤為何。 |
getTrashThreads(start, max) | GmailThread[] | 擷取一系列垃圾桶中的郵件串,不論標籤為何。 |
getUserLabelByName(name) | GmailLabel | 依標籤名稱擷取標籤。 |
getUserLabels() | GmailLabel[] | 擷取使用者建立的標籤清單。 |
markMessageRead(message) | GmailApp | 將這則訊息標示為已讀,並強制重新整理訊息。 |
markMessageUnread(message) | GmailApp | 將這則訊息標示為未讀,並強制重新整理訊息。 |
markMessagesRead(messages) | GmailApp | 將這些郵件標示為已讀取,並強制重新整理郵件。 |
markMessagesUnread(messages) | GmailApp | 將這些訊息標示為未讀,並強制重新整理訊息。 |
markThreadImportant(thread) | GmailApp | 將這個討論串標示為重要,並強制重新整理討論串。 |
markThreadRead(thread) | GmailApp | 將這個討論串標示為已讀,並強制重新整理討論串。 |
markThreadUnimportant(thread) | GmailApp | 將這個討論串標示為不重要,並強制重新整理討論串。 |
markThreadUnread(thread) | GmailApp | 將這個討論串標示為未讀,並強制重新整理討論串。 |
markThreadsImportant(threads) | GmailApp | 將這些討論串標示為重要,並強制重新整理討論串。 |
markThreadsRead(threads) | GmailApp | 將這些討論串標示為已讀,並強制重新整理討論串。 |
markThreadsUnimportant(threads) | GmailApp | 將這些討論串標示為不重要,並強制重新整理討論串。 |
markThreadsUnread(threads) | GmailApp | 將這些討論串標示為未讀,並強制重新整理討論串。 |
moveMessageToTrash(message) | GmailApp | 郵件會移至垃圾桶,並強制重新整理。 |
moveMessagesToTrash(messages) | GmailApp | 將指定郵件移至垃圾桶,並強制重新整理郵件。 |
moveThreadToArchive(thread) | GmailApp | 將這個執行緒移至封存,並強制重新整理執行緒。 |
moveThreadToInbox(thread) | GmailApp | 將這個執行緒移至收件匣,並強制重新整理執行緒。 |
moveThreadToSpam(thread) | GmailApp | 將這個執行緒移至垃圾訊息,並強制重新整理執行緒。 |
moveThreadToTrash(thread) | GmailApp | 將這個執行緒移至垃圾桶,並強制重新整理執行緒。 |
moveThreadsToArchive(threads) | GmailApp | 將這些執行緒移至封存,並強制重新整理執行緒。 |
moveThreadsToInbox(threads) | GmailApp | 將這些討論串移至收件匣,並強制重新整理討論串。 |
moveThreadsToSpam(threads) | GmailApp | 將這些討論串移至垃圾內容,並強制重新整理討論串。 |
moveThreadsToTrash(threads) | GmailApp | 將這些討論串移至垃圾桶,並強制重新整理討論串。 |
refreshMessage(message) | GmailApp | 從 Gmail 重新載入郵件和相關狀態 (如果標籤、已讀狀態等已變更,這項功能就很有用)。 |
refreshMessages(messages) | GmailApp | 從 Gmail 重新載入郵件和相關狀態 (如果標籤、已讀狀態等已變更,這項功能就非常實用)。 |
refreshThread(thread) | GmailApp | 從 Gmail 重新載入郵件串和相關狀態 (如果標籤、已讀狀態等已變更,這項功能就非常實用)。 |
refreshThreads(threads) | GmailApp | 從 Gmail 重新載入郵件串和相關狀態 (如果標籤、已讀狀態等已變更,這項功能就很有用)。 |
search(query) | GmailThread[] | 使用指定查詢搜尋 Gmail。 |
search(query, start, max) | GmailThread[] | 使用指定查詢搜尋 Gmail。 |
sendEmail(recipient, subject, body) | GmailApp | 傳送電子郵件訊息。 |
sendEmail(recipient, subject, body, options) | GmailApp | 傳送電子郵件,並可選擇是否加入引數。 |
setCurrentMessageAccessToken(accessToken) | void | 設定目前訊息存取權杖,讓指令碼存取目前的 GmailMessage 屬性。 |
starMessage(message) | GmailApp | 為郵件加上星號,並強制重新整理郵件。 |
starMessages(messages) | GmailApp | 為這些郵件加上星號,並強制重新整理郵件。 |
unstarMessage(message) | GmailApp | 移除郵件的星號,並強制重新整理郵件。 |
unstarMessages(messages) | GmailApp | 移除這些郵件的星號,並強制重新整理郵件。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-04 (世界標準時間)。
[null,null,["上次更新時間:2025-08-04 (世界標準時間)。"],[[["\u003cp\u003eThe Gmail service in Google Apps Script allows for comprehensive management of Gmail accounts, including sending emails, managing drafts, labels, and messages.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGmailApp\u003c/code\u003e class provides access to various Gmail functionalities, such as creating drafts, managing labels, searching emails, and retrieving threads.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGmailThread\u003c/code\u003e and \u003ccode\u003eGmailMessage\u003c/code\u003e objects offer methods to interact with email threads and individual messages respectively, including marking them as read, starring, moving them to different folders, and replying to them.\u003c/p\u003e\n"],["\u003cp\u003eYou can use dedicated classes like \u003ccode\u003eGmailAttachment\u003c/code\u003e, \u003ccode\u003eGmailDraft\u003c/code\u003e, and \u003ccode\u003eGmailLabel\u003c/code\u003e to work with email attachments, drafts, and labels respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe service offers methods to search for emails based on queries and to manage spam, starred, priority inbox, and trash threads.\u003c/p\u003e\n"]]],["Gmail enables users to manage emails, drafts, and labels. Key actions include creating and managing labels with `createLabel` and `deleteLabel`, retrieving them with `getUserLabelByName`, and listing all labels with `getUserLabels`. It also allows creating drafts via `createDraft`, managing threads using methods like `getInboxThreads` and managing message using methods like `getMessageById`. Users can search with `search`, send emails with `sendEmail`, mark messages/threads as read/unread, and move them to the trash/spam/archive. Attachment data can be read/write with methods such as `getBytes` and `setBytes`.\n"],null,[]]