> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Gmail

> Search, read, and send emails via Gmail.

Search, read, and send emails. By default, exposes `query_gmail` for searching and reading. Enable `write=True` to also expose `update_gmail` for drafting and sending.

```python theme={null}
from agno.agent import Agent
from agno.context.gmail import GmailContextProvider

gmail = GmailContextProvider()

agent = Agent(
    model=...,
    tools=gmail.get_tools(),
)

await agent.aprint_response("Do I have any unread emails from the engineering team?")
```

## Authentication

Gmail requires Google OAuth or a service account with domain-wide delegation.

**OAuth (Personal)**

Set these environment variables:

```shell theme={null}
export GOOGLE_CLIENT_ID=...
export GOOGLE_CLIENT_SECRET=...
export GOOGLE_PROJECT_ID=...
```

Opens browser on first use. Token cached to `gmail_token.json`.

**Service Account**

```shell theme={null}
export GOOGLE_SERVICE_ACCOUNT_FILE=/path/to/service-account.json
export GOOGLE_DELEGATED_USER=user@domain.com
```

`delegated_user` is required because service accounts have no inbox.

## Configuration

| Parameter | Type | Default | Description |
| - | - | - | - |
| `id` | `str` | `"gmail"` | Tools become `query_<id>` and `update_<id>`. |
| `model` | `Model` | `None` | Model for sub-agents. |
| `read` | `bool` | `True` | Expose `query_gmail`. |
| `write` | `bool` | `False` | Expose `update_gmail`. Disabled by default for safety. |
| `mode` | `ContextMode` | `default` | See [Mode](https://agno-v2.mintlify.site/context-providers/overview.md#mode). |

## Tools Exposed

| Tool | Description |
| - | - |
| `query_gmail` | Search emails, get messages, get threads, list labels. Requires `read=True` (default). |
| `update_gmail` | Create drafts, send emails, send replies, manage labels. Requires `write=True`. |

## Example queries

For draft/send queries, enable writes: `GmailContextProvider(write=True)`

| Query | What happens |
| - | - |
| "Find emails from Alice about the Q4 report" | Searches with `from:alice subject:Q4 report` |
| "Summarize the thread about the API outage" | Gets thread and synthesizes |
| "Draft a reply saying I'll review it tomorrow" | Creates draft in thread |
| "Send a quick update to the team about the fix" | Composes and sends |

## Resources

> **[GmailTools Reference](https://agno-v2.mintlify.site/tools/toolkits/social/gmail.md)**
>
> All methods and OAuth setup

> **[Cookbook Example](https://github.com/agno-agi/agno/blob/main/cookbook/12_context/18_gmail.py)**
>
> Working example


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.