ConnectOnionConnectOnion
DocsGmail

Gmail

Give your agents full Gmail access. Read, search, organize, and analyze emails.

Quick Start

quickstart.py
1from connectonion import Agent, Gmail 2 3gmail = Gmail() 4agent = Agent("assistant", tools=[gmail]) 5 6agent.input("Show me my recent emails") 7agent.input("Find emails from alice@example.com")

Setup

Authenticate with Google:

Terminal
$co auth google

Your agent can now read and manage Gmail.

Agent Methods

Reading Emails

read_inbox(last=10, unread=False)

Read emails from inbox

  • last - Number of emails (default: 10)
  • unread - Only unread emails (default: False)

get_sent_emails(max_results=10)

Get emails you sent

get_all_emails(max_results=50)

Get emails from all folders (inbox, sent, archive)

get_email_body(email_id)

Get full email content

get_email_attachments(email_id)

List attachments (filename, size)

Search

search_emails(query, max_results=10)

Search using Gmail query syntax

Example queries:

  • "from:alice@example.com"
  • "subject:meeting"
  • "is:unread has:attachment"
  • "after:2024/01/01 before:2024/06/01"

Actions

mark_read(email_id)

Mark email as read

mark_unread(email_id)

Mark email as unread

archive_email(email_id)

Archive email (remove from inbox)

star_email(email_id)

Add star to email

Labels

get_labels()

List all Gmail labels

add_label(email_id, label)

Add label to email

get_emails_with_label(label, max_results=10)

Get emails with specific label

Stats

count_unread()

Count unread emails

CRM Features

get_all_contacts(max_emails=500)

Extract all unique contacts from emails

  • Fast regex-based extraction
  • Returns list of contacts with email and name

analyze_contact(email, max_emails=50)

Analyze specific contact using LLM

  • Provides relationship context, topics, patterns, tags
  • Example: gmail.analyze_contact("alice@example.com")

Complete Example

complete_example.py
1from connectonion import Agent, Gmail, Memory 2 3gmail = Gmail() 4memory = Memory() 5 6agent = Agent( 7 name="email-assistant", 8 tools=[gmail, memory], 9 system_prompt="You help manage emails and remember important info." 10) 11 12# Various tasks your agent can now do: 13agent.input("Check unread emails and save important deadlines to memory") 14agent.input("Archive all newsletter emails from this week") 15agent.input("Find all emails from alice@example.com about the project") 16agent.input("Who are my top 10 most frequent contacts?") 17agent.input("Analyze my relationship with bob@company.com")

Troubleshooting

Missing gmail.readonly scope

Run co auth google

Credentials not found

Run co auth google