This Service lets you send email, compose drafts, manage labels, mark messages and threads, and conduct a variety of other Gmail account management tasks. See also Mail Service, a simpler service that only allows the sending of email.
Class: GmailApp
Provides access to Gmail threads, messages, and labels.
| Method | Description | Return Type | Return Description | Status | Implementation |
|---|---|---|---|---|---|
| createDraft(String,String,String,Object) | completed | link | |||
| createDraft(String,String,String) | completed | link | |||
| createLabel(String) | Create a new user label of the given name. | GmailLabel | the newly created label | completed | link |
| deleteLabel(GmailLabel) | Deletes the specified label. | GmailApp | the Gmail service, useful for chaining | completed | link |
| getAliases() | Gets a list of the emails that are set up as aliases for this account in Gmail. | String[] | an array of aliases for this account | completed | link |
| getDraft(String) | Retrieve an email message draft by ID. | GmailDraft | the draft with the given ID | completed | link |
| getDraftMessages() | Retrieves all draft messages. | GmailMessage[] | an array of draft Gmail messages | completed | link |
| getDrafts() | Gets all Gmail draft messages. | GmailDraft[] | an array of Gmail draft messages | completed | link |
| getInboxThreads() | Retrieves all Inbox threads irrespective of labels. | GmailThread[] | an array of Gmail threads in the Inbox | completed | link |
| getInboxThreads(Integer,Integer) | completed | link | |||
| getInboxUnreadCount() | Gets the number of unread threads in the inbox. | Integer | the number of threads in the inbox that have unread messages | completed | link |
| getMessageById(String) | Gets a message by ID. | GmailMessage | the message with the given ID | completed | link |
| getMessagesForThread(GmailThread) | Retrieve all messages in the specified thread. | GmailMessage[] | array of messages corresponding to this thread | completed | link |
| getMessagesForThreads(GmailThread) | Retrieve all messages in the specified threads. | GmailMessage[][] | an array of arrays of messages, where each item in the outer array corresponds to a thread and the inner array contains the messages in that thread | completed | link |
| getPriorityInboxThreads() | Retrieves all Priority Inbox threads irrespective of labels. | GmailThread[] | an array of Gmail threads in the Priority Inbox | completed | link |
| getPriorityInboxThreads(Integer,Integer) | completed | link | |||
| getPriorityInboxUnreadCount() | Gets the number of unread threads in the Priority Inbox. | Integer | the number of threads in the Priority Inbox that have unread messages | completed | link |
| getSpamThreads() | Retrieves all spam threads irrespective of labels. | GmailThread[] | an array of Gmail threads in the spam folder | completed | link |
| getSpamThreads(Integer,Integer) | completed | link | |||
| getSpamUnreadCount() | Gets the number of unread threads that are spam. | Integer | the number spam threads that have unread messages | completed | link |
| getStarredThreads() | Retrieves all starred threads irrespective of labels. | GmailThread[] | an array of starred Gmail threads | completed | link |
| getStarredThreads(Integer,Integer) | completed | link | |||
| getStarredUnreadCount() | Gets the number of unread threads that are starred. | Integer | the number of starred threads that have unread messages | completed | link |
| getThreadById(String) | Gets a thread by ID. | GmailThread|null | The thread with the given ID or null if not found. | completed | link |
| getTrashThreads() | Retrieves all trash threads irrespective of labels. | GmailThread[] | an array of Gmail threads in the trash | completed | link |
| getTrashThreads(Integer,Integer) | completed | link | |||
| getUserLabelByName(String) | Retrieves a label given the label name. | GmailLabel | the Gmail label with the given name | completed | link |
| getUserLabels() | Retrieves a list of user-created labels. | GmailLabel[] | array of user created labels | completed | link |
| markMessageRead(GmailMessage) | Marks this message read and forces the message to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markMessagesRead(GmailMessage) | Marks these messages read and forces the messages to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markMessagesUnread(GmailMessage) | Marks these messages unread and forces the messages to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markMessageUnread(GmailMessage) | Marks this message unread and forces the message to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadImportant(GmailThread) | Marks this thread as important and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadRead(GmailThread) | Marks this thread as read and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadsImportant(GmailThread) | Marks these threads as important and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadsRead(GmailThread) | Marks these threads as read and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadsUnimportant(GmailThread) | Marks these threads as unimportant and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadsUnread(GmailThread) | Marks these threads as unread and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadUnimportant(GmailThread) | Marks this thread as unimportant and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| markThreadUnread(GmailThread) | Marks this thread unread and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveMessagesToTrash(GmailMessage) | Moves the specified messages to the trash and forces the messages to refresh. | GmailApp | the Gmail service (useful for chaining) | completed | link |
| moveMessageToTrash(GmailMessage) | Moves the message to the trash and forces the message to refresh. | GmailApp | the Gmail service (useful for chaining) | completed | link |
| moveThreadsToArchive(GmailThread) | Moves these threads to the archive and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveThreadsToInbox(GmailThread) | Moves these threads to the inbox and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveThreadsToSpam(GmailThread) | Moves these threads to spam and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveThreadsToTrash(GmailThread) | Moves these threads to the trash and forces the threads to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveThreadToArchive(GmailThread) | Moves this thread to the archive and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveThreadToInbox(GmailThread) | Moves this thread to the inbox and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveThreadToSpam(GmailThread) | Moves this thread to spam and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| moveThreadToTrash(GmailThread) | Moves this thread to the trash and forces the thread to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| refreshMessage(GmailMessage) | Reloads the message and associated state from Gmail (useful in case the labels, read state, etc., have changed). | GmailApp | the Gmail service, useful for chaining | completed | link |
| refreshMessages(GmailMessage) | Reloads the messages and associated state from Gmail (useful in case the labels, read state, etc., have changed). | GmailApp | the Gmail service, useful for chaining | completed | link |
| refreshThread(GmailThread) | Reloads the thread and associated state from Gmail (useful in case the labels, read state, etc., have changed). | GmailApp | the Gmail service, useful for chaining | completed | link |
| refreshThreads(GmailThread) | Reloads the threads and associated state from Gmail (useful in case the labels, read state, etc., have changed). | GmailApp | the Gmail service, useful for chaining | completed | link |
| search(String,Integer,Integer) | completed | link | |||
| search(String) | Search Gmail with the given query. | GmailThread[] | an array of Gmail threads matching this query | completed | link |
| sendEmail(String,String,String,Object) | completed | link | |||
| sendEmail(String,String,String) | completed | link | |||
| setCurrentMessageAccessToken(String) | Sets the current message access token that enables the script to access the current GmailMessage properties. | completed | link | ||
| starMessage(GmailMessage) | Adds a star to this message and forces the message to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| starMessages(GmailMessage) | Adds stars to these messages and forces the messages to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| unstarMessage(GmailMessage) | Removes a star from this message and forces the message to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
| unstarMessages(GmailMessage) | Removes stars from these messages and forces the messages to refresh. | GmailApp | the Gmail service, useful for chaining | completed | link |
Class: GmailAttachment
An attachment from Gmail. This is a regular Blob except that it has an extra getSize() method that is faster than calling getBytes().length and does not count against the Gmail read quota.
| Method | Description | Return Type | Return Description | Status | Implementation |
|---|---|---|---|---|---|
| copyBlob() | Returns a copy of this blob. | Blob | The new copy. | completed | link |
| getAs(String) | Return the data inside this object as a blob converted to the specified content type. This method adds the appropriate extension to the filename—for example, "myfile.pdf". However, it assumes that the part of the filename that follows the last period (if any) is an existing extension that should be replaced. Consequently, "ShoppingList.12.25.2014" becomes "ShoppingList.12.25.pdf". | Blob | The data as a blob. | completed | link |
| getBytes() | Gets the data stored in this blob. | Byte[] | The stored bytes. | completed | link |
| getContentType() | Gets the content type of the bytes in this blob. | String|null | The content type of this data, if known, or null. | completed | link |
| getDataAsString() | Gets the data of this blob as a String with UTF-8 encoding. | String | The data as a string. | completed | link |
| getDataAsString(String) | Gets the data of this blob as a string with the specified encoding. | String | The data as a string. | completed | link |
| getHash() | Gets the SHA1 content hash for this attachment. This method does not count against the Gmail read quota. | String | The SHA1 content hash, as a string. | completed | link |
| getName() | Gets the name of this blob. | String|null | The name of this data, if known, or null. | completed | link |
| getSize() | Gets the size of this attachment. This method is faster than calling getBytes().length and does not count against the Gmail read quota. | Integer | The size of the attachment, in bytes. | completed | link |
| isGoogleType() | Returns whether this blob is a Google Workspace file (Sheets, Docs, etc.). | Boolean | true if this blob is a Google Workspace file; false if not. | completed | link |
| setBytes(Byte) | Sets the data stored in this blob. | Blob | This blob, for chaining. | completed | link |
| setContentType(String) | Sets the content type of the bytes in this blob. | Blob | This blob, for chaining. | completed | link |
| setContentTypeFromExtension() | Sets the content type of the bytes in this blob based on the file extension. The contentType is null if it cannot be guessed from its extension. | Blob | This blob, for chaining. | completed | link |
| setDataFromString(String,String) | completed | link | |||
| setDataFromString(String) | Sets the data of this blob from a string with UTF-8 encoding. | Blob | This blob, for chaining. | completed | link |
| setName(String) | Sets the name of this blob. | Blob | This blob, for chaining. | completed | link |
Class: GmailDraft
A user-created draft message in a user's Gmail account.
| Method | Description | Return Type | Return Description | Status | Implementation |
|---|---|---|---|---|---|
| deleteDraft() | Deletes this draft message. | completed | link | ||
| getId() | Gets the ID of this draft message. | String | the draft ID | completed | link |
| getMessage() | Returns a GmailMessage representing this draft. | GmailMessage | the message that represents the contents of this draft | completed | link |
| getMessageId() | Returns the ID of the GmailMessage representing this draft. | String | the message ID | completed | link |
| send() | Sends this draft email message. The size of the email (including headers) is quota limited. | GmailMessage | the newly sent message | completed | link |
| update(String,String,String,Object) | completed | link | |||
| update(String,String,String) | completed | link |
Class: GmailLabel
A user-created label in a user's Gmail account.
| Method | Description | Return Type | Return Description | Status | Implementation |
|---|---|---|---|---|---|
| addToThread(GmailThread) | Adds this label to the given thread and forces the thread to refresh (GmailThread.refresh()). | GmailLabel | This label, for chaining. | completed | link |
| addToThreads(GmailThread) | Adds this label to the given threads and forces the threads to refresh. You can add labels for up to 100 threads per batch. | GmailLabel | This label, for chaining. | completed | link |
| deleteLabel() | Deletes this label. | completed | link | ||
| getId() | Gets the id of this label. | String | The id of the label. | completed | link |
| getName() | Gets the name of this label. | String | The name of the label. | completed | link |
| getThreads() | Gets the threads that are marked with this label. | GmailThread[] | An array of threads marked with this label. | completed | link |
| getThreads(Integer,Integer) | completed | link | |||
| getUnreadCount() | Gets the number of unread threads tagged with this label. | Integer | The number of unread labeled threads. | completed | link |
| removeFromThread(GmailThread) | Removes this label from the given thread and forces the thread to refresh. | GmailLabel | This label, for chaining. | completed | link |
| removeFromThreads(GmailThread) | Removes this label from the given threads and forces the threads to refresh. You can remove labels for up to 100 threads per batch. | GmailLabel | This label, for chaining. | completed | link |
Class: GmailMessage
A message in a user's Gmail account.
| Method | Description | Return Type | Return Description | Status | Implementation |
|---|---|---|---|---|---|
| createDraftReply(String,Object) | completed | link | |||
| createDraftReply(String) | Creates a draft message replying to the sender of this message using the reply-to address. The size of the email (including headers) is quota limited. | GmailDraft | The newly created draft message. | completed | link |
| createDraftReplyAll(String,Object) | completed | link | |||
| createDraftReplyAll(String) | Creates a draft message replying to the sender using the reply-to address and all recipients of this message. The size of the email (including headers) is quota limited. | GmailDraft | The newly created draft message. | completed | link |
| forward(String,Object) | completed | link | |||
| forward(String) | Forwards this message to new recipients. The size of the email (including headers) is quota limited. | GmailMessage | This message, useful for chaining. | completed | link |
| getAttachments() | Gets all the attachments for this message. | GmailAttachment[] | An array of Blob attachments for this message. | completed | link |
| getAttachments(Object) | Gets all the attachments for this message. | GmailAttachment[] | An array of Blob attachments for this message. | completed | link |
| getBcc() | Gets the comma-separated recipients bcc'd on this message. | String | The comma-separated recipients bcc'd on this message. | completed | link |
| getBody() | Gets the HTML content of the body of this message. | String | The body content of this message. | completed | link |
| getCc() | Gets the comma-separated recipients cc'd on this message. | String | The comma-separated recipients cc'd on this message. | completed | link |
| getDate() | Gets the date and time of this message. | Date | The date and time of this message. | completed | link |
| getFrom() | Gets the sender of this message. | String | The email address of the message sender. | completed | link |
| getHeader(String) | Gets the value of an RFC 2822 header given the header name. | String | The value of the header, or an empty string if the header doesn't exist in the message. | not started | |
| getId() | Gets the ID of this message. | String | The message ID. | completed | link |
| getPlainBody() | Gets the content of the body of this message without HTML formatting. This is more complex than getBody() and takes longer. | String | The plain body content of this message. | completed | link |
| getRawContent() | Gets the raw content of this message. This is equivalent to "Show Original" in the Gmail UI. | String | The raw content of this message. | completed | link |
| getReplyTo() | Gets the reply-to address of this message (usually the sender). | String | The email address for replies. | completed | link |
| getSubject() | Gets the subject of this message. | String | The subject of this message. | completed | link |
| getThread() | Gets the thread that contains this message. | GmailThread | The GmailThread that contains this message. | completed | link |
| getTo() | Gets the comma-separated recipients of this message. | String | The comma-separated recipients of this message. | completed | link |
| isDraft() | Gets whether this message is a draft. | Boolean | Whether this message is a draft. | completed | link |
| isInChats() | Gets whether this message is a chat. | Boolean | Whether this message is a chat. | completed | link |
| isInInbox() | Gets whether this message is in the inbox. | Boolean | Whether this message is in the inbox. | completed | link |
| isInPriorityInbox() | Returns true if this message is in the priority inbox; returns false otherwise. | Boolean | Whether this message is in the priority inbox. | completed | link |
| isInTrash() | Gets whether this message is in the trash. | Boolean | Whether this message is in the trash. | completed | link |
| isStarred() | Gets whether this message is starred. | Boolean | Whether this message is starred. | completed | link |
| isUnread() | Gets whether this message is unread. | Boolean | The unread status of this message. | completed | link |
| markRead() | Marks the message as read. | GmailMessage | This GmailMessage, useful for chaining. | completed | link |
| markUnread() | Marks the message as unread. | GmailMessage | This GmailMessage, useful for chaining. | completed | link |
| moveToTrash() | Moves the message to the trash. | GmailMessage | This GmailMessage, useful for chaining. | completed | link |
| refresh() | Reloads this message and associated state from Gmail (useful in case the labels, read state, etc., have changed). | GmailMessage | This message for chaining. | completed | link |
| reply(String,Object) | completed | link | |||
| reply(String) | Replies to the sender of this message using the reply-to address. The size of the email (including headers) is quota limited. | GmailMessage | This message, useful for chaining. | completed | link |
| replyAll(String,Object) | completed | link | |||
| replyAll(String) | Replies to the sender using the reply-to address and all recipients of this message. The size of the email (including headers) is quota limited. | GmailMessage | This message,useful for chaining. | completed | link |
| star() | Stars the message. | GmailMessage | This GmailMessage, useful for chaining. | completed | link |
| unstar() | Unstars the message. | GmailMessage | This GmailMessage, useful for chaining. | completed | link |
Class: GmailThread
A thread in a user's Gmail account.
| Method | Description | Return Type | Return Description | Status | Implementation |
|---|---|---|---|---|---|
| addLabel(GmailLabel) | Adds this label to the thread. | GmailThread | this thread, useful for chaining | completed | link |
| createDraftReply(String,Object) | completed | link | |||
| createDraftReply(String) | Creates a draft message replying to the sender of the last message in this thread using the reply-to address. The size of the email (including headers) is quota limited. | GmailDraft | the newly created draft message | completed | link |
| createDraftReplyAll(String,Object) | completed | link | |||
| createDraftReplyAll(String) | Creates a draft message replying to the sender of the last message in this thread, using the reply-to address and all recipients of this message. The size of the email (including headers) is quota limited. | GmailDraft | the newly created draft message | completed | link |
| getFirstMessageSubject() | Gets the subject of the first message in the thread. | String | the subject of the first message in the thread | completed | link |
| getId() | Gets the ID of this thread. The ID of a thread varies based on the messages it contains; for a consistent ID for a particular message in the thread, call getMessages()[0].getId() instead. | String | the ID of this thread | completed | link |
| getLabels() | Returns the user-created labels on this thread. | GmailLabel[] | an array of labels for this thread | completed | link |
| getLastMessageDate() | Gets the date of this thread's most recent message. | Date | the date of the most recent message in the thread | completed | link |
| getMessageCount() | Returns the number of messages in the thread. | Integer | the number of messages in the thread | completed | link |
| getMessages() | Gets the messages in this thread. | GmailMessage[] | an array of Gmail messages in this thread | completed | link |
| getPermalink() | Gets a permalink for this thread. | String | the permalink for this thread | completed | link |
| hasStarredMessages() | Returns whether the thread has any starred messages. | Boolean | true if the thread has any starred messages | completed | link |
| isImportant() | Returns whether the thread is marked as important. | Boolean | Whether the thread is marked as important. | completed | link |
| isInChats() | Returns whether the thread is labeled a chat. | Boolean | true if the thread is labeled a chat | completed | link |
| isInInbox() | Returns whether the thread is in the inbox. | Boolean | true if the thread is in the inbox | completed | link |
| isInPriorityInbox() | Returns true if this thread is in the priority inbox; returns false otherwise. | Boolean | true if the thread is in the priority inbox | completed | link |
| isInSpam() | Returns whether the thread is marked as spam. | Boolean | Whether this thread is marked as spam. | completed | link |
| isInTrash() | Returns whether the thread is in the trash. | Boolean | true if the thread is in the trash | completed | link |
| isUnread() | Returns whether the thread has any unread messages. | Boolean | true if there are unread messages | completed | link |
| markImportant() | Marks this thread as important. | GmailThread | this thread, useful for chaining | completed | link |
| markRead() | Marks this thread as read. | GmailThread | this thread, useful for chaining | completed | link |
| markUnimportant() | Marks this thread as unimportant. | GmailThread | this thread, useful for chaining | completed | link |
| markUnread() | Marks this thread as unread. | GmailThread | this thread, useful for chaining | completed | link |
| moveToArchive() | Moves this thread to the archive. | GmailThread | this thread, useful for chaining | completed | link |
| moveToInbox() | Moves this thread to the inbox. | GmailThread | this thread, useful for chaining | completed | link |
| moveToSpam() | Moves this thread to spam. | GmailThread | this thread, useful for chaining | completed | link |
| moveToTrash() | Moves this thread to the trash. | GmailThread | this thread, useful for chaining | completed | link |
| refresh() | Reloads this thread, and associated state from Gmail (useful in case the labels, read state, etc., have changed). | GmailThread | this thread, useful for chaining | completed | link |
| removeLabel(GmailLabel) | Removes this label from the thread. | GmailThread | this thread, useful for chaining | completed | link |
| reply(String,Object) | completed | link | |||
| reply(String) | Reply to the sender of the last message on this thread using the replyTo address. | GmailThread | this thread, useful for chaining | completed | link |
| replyAll(String,Object) | completed | link | |||
| replyAll(String) | Reply to the sender (using the replyTo address), and all recipients of the last message on this thread. | GmailThread | this thread, useful for chaining | completed | link |