Skip to main content

Gmail

Send, search, and read emails via the Gmail API. Uses Google’s OAuth2 authentication.

Prerequisites

1

Install googleapis

npm install googleapis
2

Create OAuth2 Credentials

Go to Google Cloud Console, enable the Gmail API, and create OAuth2 credentials. Download credentials.json.
3

Generate Token

Run the Google OAuth flow to generate token.json. See the Gmail API quickstart.
4

Set Environment Variables

export GMAIL_CREDENTIALS_PATH=./credentials.json
export GMAIL_TOKEN_PATH=./token.json

Quick Start

import { Agent, openai, GmailToolkit } from "@radaros/core";

const gmail = new GmailToolkit();

const agent = new Agent({
  name: "email-assistant",
  model: openai("gpt-4o"),
  instructions: "You can search, read, and send emails via Gmail.",
  tools: [...gmail.getTools()],
});

const result = await agent.run("Search for my 3 most recent unread emails.");

Config

credentialsPath
string
Path to OAuth2 credentials JSON. Falls back to GMAIL_CREDENTIALS_PATH env var.
tokenPath
string
Path to saved token JSON. Falls back to GMAIL_TOKEN_PATH env var.
authClient
OAuth2Client
Pre-authenticated OAuth2 client (if you handle auth yourself).

Tools

ToolDescription
gmail_sendSend an email. Parameters: to, subject, body.
gmail_searchSearch emails. Parameters: query (Gmail search syntax), maxResults.
gmail_readRead full email content by message ID.

Search Query Examples

The gmail_search tool accepts Gmail search syntax:
QueryDescription
is:unreadAll unread emails
from:john@example.comEmails from a specific sender
subject:meetingEmails with “meeting” in subject
has:attachmentEmails with attachments
newer_than:2dEmails from the last 2 days