Skip to main content
GmailTool provides read-only access to Gmail for listing, searching, and fetching messages using the Gmail API.

Installation

Install the Google dependencies:

Authentication

GmailTool requires Google OAuth2 credentials:
  1. Create credentials using the superauth library
  2. Save credentials to a JSON file
  3. Provide the path or set GOOGLE_USER_CREDENTIALS environment variable

Constructor

str
Path to saved user credentials JSON file. Defaults to GOOGLE_USER_CREDENTIALS env var or credentials.json
CredentialRecord
Pre-loaded credentials object. Overrides credentials_path if provided

Methods

search_messages

Search Gmail using the same query syntax as the web UI.
str
required
Gmail search query (e.g., from:alice has:attachment newer_than:7d)
List[str]
Optional Gmail label IDs to filter by
str
ISO date string to filter messages after
str
ISO date string to filter messages before
int
Number of messages to return (1-50, default: 20)

list_messages

List message IDs (fast, metadata-only).
List[str]
Optional Gmail label IDs to filter by
str
Optional Gmail query string
int
Number of messages to return (1-50, default: 20)
str
Pagination token from previous call
bool
Whether to include spam and trash (default: False)

get_message

Fetch a single Gmail message (metadata only).
str
required
Gmail message ID

get_message_body

Fetch a single Gmail message body for display or summarization.
str
required
Gmail message ID
str
“text” or “html” (default: “text”)
int
Max characters to return (default: 50000)

Usage

Basic setup

Searching emails

Reading message bodies

Privacy and security

GmailTool is read-only and cannot send emails, delete messages, or modify your Gmail account. It requires explicit OAuth consent from users.

Error handling

Source reference

src/agentor/tools/gmail.py:19
Last modified on August 28, 2026