AI-generated Key Takeaways
-
The Advanced Gmail service in Apps Script lets you use the Gmail API to interact with your mailbox, offering more features than the built-in service.
-
This advanced service requires enabling before use and provides access to detailed information about threads, messages, and labels.
-
You can utilize the provided sample code snippets to list label information, inbox snippets, and recent history within your Gmail account.
-
The Gmail API might limit data returned in list requests for performance, requiring follow-up 'get' requests for detailed information.
-
For comprehensive details, refer to the reference documentation, support guide, and sample code on GitHub.
The Advanced Gmail service allows you to use the Gmail API in Apps Script. Much like Apps Script's built-in Gmail service, this API allows scripts to find and modify threads, messages, and labels in a Gmail mailbox. In most cases, the built-in service is easier to use, but this advanced service provides a few extra features and access to more detailed information about Gmail content.
Reference
For detailed information on this service, see the reference documentation for the Gmail API. Like all advanced services in Apps Script, the advanced Gmail service uses the same objects, methods, and parameters as the public API. For more information, see How method signatures are determined.
To report issues and find other support, see the Gmail support guide.
Sample code
The sample code below uses version 1 of the API.
List label information
The following example demonstrates how to list all the user's label information. This includes the label name, type, ID and visibility settings.
List inbox snippets
The following example demonstrates how to list text snippets associated with each thread in the user's Inbox. Notice the use of page tokens to access the full list of results.
List recent history
The following example demonstrates how to log recent activity history. Specifically, this example recovers the history record ID associated with the user's most recently sent message, and then logs the message IDs of every message that has changed since that time. Each changed message is only logged once, no matter how many change events are in the history records. Notice the use of page tokens to access the full list of results.
List messages
The following example demonstrates how to list the Gmail user's unread messages.