Google Apps Script

Gmail Service

This service allows scripts to send email and access a user's Gmail account. See also Mail Service. Unlike Gmail Service, Mail Service's sole purpose is sending email; it cannot access a user's Gmail account.

Classes

NameBrief description
GmailAppProvides access to Gmail threads, messages, and labels.
GmailAttachmentAn attachment from Gmail.
GmailLabelA user-created label in a user's Gmail account.
GmailMessageA message in a user's Gmail account.
GmailThreadA thread in a user's Gmail account.

Class GmailApp

Methods

MethodReturn typeBrief description
createLabel(name)GmailLabelCreate a new user label of the given name.
deleteLabel(label)GmailAppDeletes the specified label.
getAliases()String[]Gets a list of the emails that are set up as aliases for this account in Gmail.
getChatThreads()GmailThread[]Retrieves all chat threads irrespective of labels.
getChatThreads(start, max)GmailThread[]Retrieves a range of chat threads irrespective of labels.
getDraftMessages()GmailMessage[]Retrieves all draft messages.
getInboxThreads()GmailThread[]Retrieves all Inbox threads irrespective of labels.
getInboxThreads(start, max)GmailThread[]Retrieves a range of Inbox threads irrespective of labels.
getInboxUnreadCount()IntegerGets the number of unread threads in the inbox.
getMessageById(id)GmailMessageGets a message by id.
getMessagesForThread(thread)GmailMessage[]Retrieve all messages in the specified thread.
getMessagesForThreads(threads)GmailMessage[][]Retrieve all messages in the specified threads.
getPriorityInboxThreads()GmailThread[]Retrieves all Priority Inbox threads irrespective of labels.
getPriorityInboxThreads(start, max)GmailThread[]Retrieves a range of Priority Inbox threads irrespective of labels.
getPriorityInboxUnreadCount()IntegerGets the number of unread threads in the Priority Inbox.
getSpamThreads()GmailThread[]Retrieves all spam threads irrespective of labels.
getSpamThreads(start, max)GmailThread[]Retrieves a range of spam threads irrespective of labels.
getSpamUnreadCount()IntegerGets the number of unread threads that are spam.
getStarredThreads()GmailThread[]Retrieves all starred threads irrespective of labels.
getStarredThreads(start, max)GmailThread[]Retrieves a range of starred threads irrespective of labels.
getStarredUnreadCount()IntegerGets the number of unread threads that are starred.
getThreadById(id)GmailThreadGets a thread by id.
getTrashThreads()GmailThread[]Retrieves all trash threads irrespective of labels.
getTrashThreads(start, max)GmailThread[]Retrieves a range of trash threads irrespective of labels.
getUserLabelByName(name)GmailLabelRetrieves a label given the label name.
getUserLabels()GmailLabel[]Retrieves a list of user-created labels.
markMessageRead(message)GmailAppMarks this message read and forces the message to refresh.
markMessageUnread(message)GmailAppMarks this message unread and forces the message to refresh.
markMessagesRead(messages)GmailAppMarks these messages read and forces the messages to refresh.
markMessagesUnread(messages)GmailAppMarks these messages unread and forces the messages to refresh.
markThreadImportant(thread)GmailAppMarks this thread as important and forces the thread to refresh.
markThreadRead(thread)GmailAppMarks this thread as read and forces the thread to refresh.
markThreadUnimportant(thread)GmailAppMarks this thread as unimportant and forces the thread to refresh.
markThreadUnread(thread)GmailAppMarks this thread unread and forces the thread to refresh.
markThreadsImportant(threads)GmailAppMarks these threads as important and forces the threads to refresh.
markThreadsRead(threads)GmailAppMarks these threads as read and forces the threads to refresh.
markThreadsUnimportant(threads)GmailAppMarks these threads as unimportant and forces the threads to refresh.
markThreadsUnread(threads)GmailAppMarks these threads as unread and forces the threads to refresh.
moveMessageToTrash(message)GmailAppMoves the message to the trash and forces the message to refresh.
moveMessagesToTrash(messages)GmailAppMoves the specified messages to the trash and forces the messages to refresh.
moveThreadToArchive(thread)GmailAppMoves this thread to the archive and forces the thread to refresh.
moveThreadToInbox(thread)GmailAppMoves this thread to the inbox and forces the thread to refresh.
moveThreadToSpam(thread)GmailAppMoves this thread to spam and forces the thread to refresh.
moveThreadToTrash(thread)GmailAppMoves this thread to the trash and forces the thread to refresh.
moveThreadsToArchive(threads)GmailAppMoves these threads to the archive and forces the threads to refresh.
moveThreadsToInbox(threads)GmailAppMoves these threads to the inbox and forces the threads to refresh.
moveThreadsToSpam(threads)GmailAppMoves these threads to spam and forces the threads to refresh.
moveThreadsToTrash(threads)GmailAppMoves these threads to the trash and forces the threads to refresh.
refreshMessage(message)GmailAppReloads the message and associated state from Gmail (useful in case the labels, read state, etc., have changed).
refreshMessages(messages)GmailAppReloads the messages and associated state from Gmail (useful in case the labels, read state, etc., have changed).
refreshThread(thread)GmailAppReloads the thread and associated state from Gmail (useful in case the labels, read state, etc., have changed).
refreshThreads(threads)GmailAppReloads the threads and associated state from Gmail (useful in case the labels, read state, etc., have changed).
search(query)GmailThread[]Search Gmail with the given query.
search(query, start, max)GmailThread[]Search Gmail with the given query.
sendEmail(recipient, subject, body)GmailAppSends an email message.
sendEmail(recipient, subject, body, options)GmailAppSends an email message with optional arguments.
starMessage(message)GmailAppAdds a star to this message and forces the message to refresh.
starMessages(messages)GmailAppAdds stars to these messages and forces the messages to refresh.
unstarMessage(message)GmailAppRemoves a star from this message and forces the message to refresh.
unstarMessages(messages)GmailAppRemoves stars from these messages and forces the messages to refresh.

Class GmailAttachment

Methods

MethodReturn typeBrief description
copyBlob()BlobReturns a copy of this blob.
getAs(contentType)BlobReturn the data inside this object as a blob converted to the specified content type.
getBytes()Byte[]Gets the data stored in this blob.
getContentType()StringGets the content type of the bytes in this blob.
getDataAsString()StringGets the data of this blob as a String with UTF-8 encoding.
getDataAsString(charset)StringGets the data of this blob as a string with the specified encoding.
getName()StringGets the name of this blob.
getSize()IntegerGets the size of this attachment.
isGoogleType()BooleanReturns whether this blob is a Google Apps file (Sheets, Docs, etc.).
setBytes(data)BlobSets the data stored in this blob.
setContentType(contentType)BlobSets the content type of the bytes in this blob.
setContentTypeFromExtension()BlobSets the content type of the bytes in this blob based on the file extension.
setDataFromString(string)BlobSets the data of this blob from a string with UTF-8 encoding.
setDataFromString(string, charset)BlobSets the data of this blob from a string with the specified encoding.
setName(name)BlobSets the name of this blob.

Class GmailLabel

Methods

MethodReturn typeBrief description
addToThread(thread)GmailLabelAdds this label to the given thread and forces the thread to refresh (GmailThread.refresh()).
addToThreads(threads)GmailLabelAdds this label to the given threads and forces the threads to refresh.
deleteLabel()voidDeletes this label.
getName()StringGets the name of this label.
getThreads()GmailThread[]Gets the threads that are marked with this label.
getThreads(start, max)GmailThread[]Gets a range of threads marked with this label.
getUnreadCount()IntegerGets the number of unread threads tagged with this label.
removeFromThread(thread)GmailLabelRemoves this label from the given thread and forces the thread to refresh.
removeFromThreads(threads)GmailLabelRemoves this label from the given threads and forces the threads to refresh.

Class GmailMessage

Methods

MethodReturn typeBrief description
forward(recipient)GmailMessageForwards this message to new recipients.
forward(recipient, options)GmailMessageForwards this message to new recipients, with optional arguments.
getAttachments()GmailAttachment[]Gets all the attachments for this message.
getBcc()StringGets the comma-separated recipients bcc'd on this message.
getBody()StringGets the HTML content of the body of this message.
getCc()StringGets the comma-separated recipients cc'd on this message.
getDate()DateGets the date and time of this message.
getFrom()StringGets the sender of this message.
getId()StringGets the id of this message.
getPlainBody()StringGets the content of the body of this message without HTML formatting.
getRawContent()StringGets the raw content of this message.
getReplyTo()StringGets the reply-to address of this message (usually the sender).
getSubject()StringGets the subject of this message.
getThread()GmailThreadGets the thread that contains this message.
getTo()StringGets the comma-separated recipient(s) of this message.
isDraft()BooleanGets whether this message is a draft.
isInChats()BooleanGets whether this message is a chat.
isInInbox()BooleanGets whether this message is in the inbox.
isInTrash()BooleanGets whether this message is in the trash.
isStarred()BooleanGets whether this message is starred.
isUnread()BooleanGets whether this message is unread.
markRead()GmailMessageMarks the message as read.
markUnread()GmailMessageMarks the message as unread.
moveToTrash()GmailMessageMoves the message to the trash.
refresh()GmailMessageReloads this message and associated state from Gmail (useful in case the labels, read state, etc., have changed).
reply(body)GmailMessageReplies to the sender of this message using the reply-to address.
reply(body, options)GmailMessageReplies to the sender of this message using the reply-to address, with optional arguments.
replyAll(body)GmailMessageReplies to the sender using the reply-to address and all recipients of this message.
replyAll(body, options)GmailMessageReplies to the sender of this message using the reply-to address and all recipients, with optional arguments.
star()GmailMessageStars the message.
unstar()GmailMessageUnstars the message.

Class GmailThread

Methods

MethodReturn typeBrief description
addLabel(label)GmailThreadAdds this label to the thread.
getFirstMessageSubject()StringGets the subject of the first message in the thread.
getId()StringGets the id of this thread.
getLabels()GmailLabel[]Returns the user-created labels on this thread.
getLastMessageDate()DateGets the date of this thread's most recent message.
getMessageCount()IntegerReturns the number of messages in the thread.
getMessages()GmailMessage[]Gets the messages in this thread.
getPermalink()StringGets a permalink for this thread.
hasStarredMessages()BooleanReturns whether the thread has any starred messages.
isImportant()BooleanReturns whether the thread is marked important.
isInChats()BooleanReturns whether the thread is labeled a chat.
isInInbox()BooleanReturns whether the thread is in the inbox.
isInSpam()BooleanReturns whether the thread is marked as spam.
isInTrash()BooleanReturns whether the thread is in the trash.
isUnread()BooleanReturns whether the thread has any unread messages.
markImportant()GmailThreadMarks this thread as important.
markRead()GmailThreadMarks this thread as read.
markUnimportant()GmailThreadMarks this thread as unimportant.
markUnread()GmailThreadMarks this thread as unread.
moveToArchive()GmailThreadMoves this thread to the archive.
moveToInbox()GmailThreadMoves this thread to the inbox.
moveToSpam()GmailThreadMoves this thread to spam.
moveToTrash()GmailThreadMoves this thread to the trash.
refresh()GmailThreadReloads this thread, and associated state from Gmail (useful in case the labels, read state, etc., have changed).
removeLabel(label)GmailThreadRemoves this label from the thread.
reply(body)GmailThreadReply to the sender of the last message on this thread using the replyTo address.
reply(body, options)GmailThreadReply to the sender of the last message on this thread using the replyTo address, with optional arguments.
replyAll(body)GmailThreadReply to the sender (using the replyTo address), and all recipients of the last message on this thread.
replyAll(body, options)GmailThreadReply to the sender (using the replyTo address), and all recipients of the last message on this thread, with optional arguments.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.