AI-generated Key Takeaways
-
The Gmail service in Google Apps Script allows for comprehensive management of Gmail accounts, including sending emails, managing drafts, labels, and messages.
-
The
GmailApp
class provides access to various Gmail functionalities, such as creating drafts, managing labels, searching emails, and retrieving threads. -
GmailThread
andGmailMessage
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. -
You can use dedicated classes like
GmailAttachment
,GmailDraft
, andGmailLabel
to work with email attachments, drafts, and labels respectively. -
The service offers methods to search for emails based on queries and to manage spam, starred, priority inbox, and trash threads.
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.
Classes
Name | Brief description |
---|---|
Gmail | Provides access to Gmail threads, messages, and labels. |
Gmail | An attachment from Gmail. |
Gmail | A user-created draft message in a user's Gmail account. |
Gmail | A user-created label in a user's Gmail account. |
Gmail | A message in a user's Gmail account. |
Gmail | A thread in a user's Gmail account. |
GmailApp
Methods
Method | Return type | Brief description |
---|---|---|
create | Gmail | Creates a draft email message. |
create | Gmail | Creates a draft email message with optional arguments. |
create | Gmail | Create a new user label of the given name. |
delete | Gmail | Deletes the specified label. |
get | String[] | Gets a list of the emails that are set up as aliases for this account in Gmail. |
get | Gmail | Retrieve an email message draft by ID. |
get | Gmail | Retrieves all draft messages. |
get | Gmail | Gets all Gmail draft messages. |
get | Gmail | Retrieves all Inbox threads irrespective of labels. |
get | Gmail | Retrieves a range of Inbox threads irrespective of labels. |
get | Integer | Gets the number of unread threads in the inbox. |
get | Gmail | Gets a message by ID. |
get | Gmail | Retrieve all messages in the specified thread. |
get | Gmail | Retrieve all messages in the specified threads. |
get | Gmail | Retrieves all Priority Inbox threads irrespective of labels. |
get | Gmail | Retrieves a range of Priority Inbox threads irrespective of labels. |
get | Integer | Gets the number of unread threads in the Priority Inbox. |
get | Gmail | Retrieves all spam threads irrespective of labels. |
get | Gmail | Retrieves a range of spam threads irrespective of labels. |
get | Integer | Gets the number of unread threads that are spam. |
get | Gmail | Retrieves all starred threads irrespective of labels. |
get | Gmail | Retrieves a range of starred threads irrespective of labels. |
get | Integer | Gets the number of unread threads that are starred. |
get | Gmail | Gets a thread by ID. |
get | Gmail | Retrieves all trash threads irrespective of labels. |
get | Gmail | Retrieves a range of trash threads irrespective of labels. |
get | Gmail | Retrieves a label given the label name. |
get | Gmail | Retrieves a list of user-created labels. |
mark | Gmail | Marks this message read and forces the message to refresh. |
mark | Gmail | Marks this message unread and forces the message to refresh. |
mark | Gmail | Marks these messages read and forces the messages to refresh. |
mark | Gmail | Marks these messages unread and forces the messages to refresh. |
mark | Gmail | Marks this thread as important and forces the thread to refresh. |
mark | Gmail | Marks this thread as read and forces the thread to refresh. |
mark | Gmail | Marks this thread as unimportant and forces the thread to refresh. |
mark | Gmail | Marks this thread unread and forces the thread to refresh. |
mark | Gmail | Marks these threads as important and forces the threads to refresh. |
mark | Gmail | Marks these threads as read and forces the threads to refresh. |
mark | Gmail | Marks these threads as unimportant and forces the threads to refresh. |
mark | Gmail | Marks these threads as unread and forces the threads to refresh. |
move | Gmail | Moves the message to the trash and forces the message to refresh. |
move | Gmail | Moves the specified messages to the trash and forces the messages to refresh. |
move | Gmail | Moves this thread to the archive and forces the thread to refresh. |
move | Gmail | Moves this thread to the inbox and forces the thread to refresh. |
move | Gmail | Moves this thread to spam and forces the thread to refresh. |
move | Gmail | Moves this thread to the trash and forces the thread to refresh. |
move | Gmail | Moves these threads to the archive and forces the threads to refresh. |
move | Gmail | Moves these threads to the inbox and forces the threads to refresh. |
move | Gmail | Moves these threads to spam and forces the threads to refresh. |
move | Gmail | Moves these threads to the trash and forces the threads to refresh. |
refresh | Gmail | Reloads the message and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
refresh | Gmail | Reloads the messages and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
refresh | Gmail | Reloads the thread and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
refresh | Gmail | Reloads the threads and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
search(query) | Gmail | Search Gmail with the given query. |
search(query, start, max) | Gmail | Search Gmail with the given query. |
send | Gmail | Sends an email message. |
send | Gmail | Sends an email message with optional arguments. |
set | void | Sets the current message
access token that enables the script to access the current Gmail properties. |
star | Gmail | Adds a star to this message and forces the message to refresh. |
star | Gmail | Adds stars to these messages and forces the messages to refresh. |
unstar | Gmail | Removes a star from this message and forces the message to refresh. |
unstar | Gmail | Removes stars from these messages and forces the messages to refresh. |
GmailAttachment
Methods
Method | Return type | Brief description |
---|---|---|
copy | Blob | Returns a copy of this blob. |
get | Blob | Return the data inside this object as a blob converted to the specified content type. |
get | Byte[] | Gets the data stored in this blob. |
get | String | Gets the content type of the bytes in this blob. |
get | String | Gets the data of this blob as a String with UTF-8 encoding. |
get | String | Gets the data of this blob as a string with the specified encoding. |
get | String | Gets the SHA1 content hash for this attachment. |
get | String | Gets the name of this blob. |
get | Integer | Gets the size of this attachment. |
is | Boolean | Returns whether this blob is a Google Workspace file (Sheets, Docs, etc.). |
set | Blob | Sets the data stored in this blob. |
set | Blob | Sets the content type of the bytes in this blob. |
set | Blob | Sets the content type of the bytes in this blob based on the file extension. |
set | Blob | Sets the data of this blob from a string with UTF-8 encoding. |
set | Blob | Sets the data of this blob from a string with the specified encoding. |
set | Blob | Sets the name of this blob. |
GmailDraft
Methods
Method | Return type | Brief description |
---|---|---|
delete | void | Deletes this draft message. |
get | String | Gets the ID of this draft message. |
get | Gmail | Returns a GmailMessage representing this draft. |
get | String | Returns the ID of the Gmail representing this draft. |
send() | Gmail | Sends this draft email message. |
update(recipient, subject, body) | Gmail | Replaces the contents of this draft message. |
update(recipient, subject, body, options) | Gmail | Replaces the contents of this draft message using optional arguments. |
GmailLabel
Methods
Method | Return type | Brief description |
---|---|---|
add | Gmail | Adds this label to the given thread and forces the thread to refresh (Gmail ). |
add | Gmail | Adds this label to the given threads and forces the threads to refresh. |
delete | void | Deletes this label. |
get | String | Gets the id of this label. |
get | String | Gets the name of this label. |
get | Gmail | Gets the threads that are marked with this label. |
get | Gmail | Gets a range of threads marked with this label. |
get | Integer | Gets the number of unread threads tagged with this label. |
remove | Gmail | Removes this label from the given thread and forces the thread to refresh. |
remove | Gmail | Removes this label from the given threads and forces the threads to refresh. |
GmailMessage
Methods
Method | Return type | Brief description |
---|---|---|
create | Gmail | Creates a draft message replying to the sender of this message using the reply-to address. |
create | Gmail | Creates a draft message replying to the sender of this message using the reply-to address, with optional arguments. |
create | Gmail | Creates a draft message replying to the sender using the reply-to address and all recipients of this message. |
create | Gmail | Creates a draft message replying to the sender of this message using the reply-to address and all recipients, with optional arguments. |
forward(recipient) | Gmail | Forwards this message to new recipients. |
forward(recipient, options) | Gmail | Forwards this message to new recipients, with optional arguments. |
get | Gmail | Gets all the attachments for this message. |
get | Gmail | Gets all the attachments for this message. |
get | String | Gets the comma-separated recipients bcc'd on this message. |
get | String | Gets the HTML content of the body of this message. |
get | String | Gets the comma-separated recipients cc'd on this message. |
get | Date | Gets the date and time of this message. |
get | String | Gets the sender of this message. |
get | String | Gets the value of an RFC 2822 header given the header name. |
get | String | Gets the ID of this message. |
get | String | Gets the content of the body of this message without HTML formatting. |
get | String | Gets the raw content of this message. |
get | String | Gets the reply-to address of this message (usually the sender). |
get | String | Gets the subject of this message. |
get | Gmail | Gets the thread that contains this message. |
get | String | Gets the comma-separated recipients of this message. |
is | Boolean | Gets whether this message is a draft. |
is | Boolean | Gets whether this message is a chat. |
is | Boolean | Gets whether this message is in the inbox. |
is | Boolean | Returns true if this message is in the priority inbox; returns false otherwise. |
is | Boolean | Gets whether this message is in the trash. |
is | Boolean | Gets whether this message is starred. |
is | Boolean | Gets whether this message is unread. |
mark | Gmail | Marks the message as read. |
mark | Gmail | Marks the message as unread. |
move | Gmail | Moves the message to the trash. |
refresh() | Gmail | Reloads this message and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
reply(body) | Gmail | Replies to the sender of this message using the reply-to address. |
reply(body, options) | Gmail | Replies to the sender of this message using the reply-to address, with optional arguments. |
reply | Gmail | Replies to the sender using the reply-to address and all recipients of this message. |
reply | Gmail | Replies to the sender of this message using the reply-to address and all recipients, with optional arguments. |
star() | Gmail | Stars the message. |
unstar() | Gmail | Unstars the message. |
GmailThread
Methods
Method | Return type | Brief description |
---|---|---|
add | Gmail | Adds this label to the thread. |
create | Gmail | Creates a draft message replying to the sender of the last message in this thread using the reply-to address. |
create | Gmail | Creates a draft message replying to the sender of the last message in this thread using the reply-to address, with optional arguments. |
create | Gmail | 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. |
create | Gmail | Creates a draft message replying to the sender of the last message in this thread, using the reply-to address and all recipients, with optional arguments. |
get | String | Gets the subject of the first message in the thread. |
get | String | Gets the ID of this thread. |
get | Gmail | Returns the user-created labels on this thread. |
get | Date | Gets the date of this thread's most recent message. |
get | Integer | Returns the number of messages in the thread. |
get | Gmail | Gets the messages in this thread. |
get | String | Gets a permalink for this thread. |
has | Boolean | Returns whether the thread has any starred messages. |
is | Boolean | Returns whether the thread is marked as important. |
is | Boolean | Returns whether the thread is labeled a chat. |
is | Boolean | Returns whether the thread is in the inbox. |
is | Boolean | Returns true if this thread is in the priority inbox; returns false otherwise. |
is | Boolean | Returns whether the thread is marked as spam. |
is | Boolean | Returns whether the thread is in the trash. |
is | Boolean | Returns whether the thread has any unread messages. |
mark | Gmail | Marks this thread as important. |
mark | Gmail | Marks this thread as read. |
mark | Gmail | Marks this thread as unimportant. |
mark | Gmail | Marks this thread as unread. |
move | Gmail | Moves this thread to the archive. |
move | Gmail | Moves this thread to the inbox. |
move | Gmail | Moves this thread to spam. |
move | Gmail | Moves this thread to the trash. |
refresh() | Gmail | Reloads this thread, and associated state from Gmail (useful in case the labels, read state, etc., have changed). |
remove | Gmail | Removes this label from the thread. |
reply(body) | Gmail | Reply to the sender of the last message on this thread using the replyTo address. |
reply(body, options) | Gmail | Reply to the sender of the last message on this thread using the replyTo address, with optional arguments. |
reply | Gmail | Reply to the sender (using the replyTo address), and all recipients of the last message on this thread. |
reply | Gmail | Reply to the sender (using the reply address), and all recipients of the last message
on this thread, with optional arguments. |