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

# Gmail

**Gmail** 允许 Agent 与 Gmail 进行交互，从而读取、搜索、发送和管理电子邮件。

## 前提条件

Gmail 工具包需要 Google API 客户端库和正确的身份验证设置。安装所需的依赖项：

```shell theme={null}
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
```

您还需要设置 Google Cloud 凭据：

1. 前往 [Google Cloud Console](https://console.cloud.google.com)
2. 创建一个项目或选择一个现有项目
3. 启用 Gmail API
4. 创建 OAuth 2.0 凭据
5. 设置环境变量：

```shell theme={null}
export GOOGLE_CLIENT_ID=your_client_id_here
export GOOGLE_CLIENT_SECRET=your_client_secret_here
export GOOGLE_PROJECT_ID=your_project_id_here
export GOOGLE_REDIRECT_URI=http://localhost  # 默认值
```

## 示例

```python cookbook/tools/gmail_tools.py theme={null}
from agno.agent import Agent
from agno.tools.gmail import GmailTools

agent = Agent(tools=[GmailTools()], show_tool_calls=True)
agent.print_response("Show me my latest 5 unread emails", markdown=True)
```

## 工具包参数

| 参数                      | 类型     | 默认值    | 描述             |
| ----------------------- | ------ | ------ | -------------- |
| `get_latest_emails`     | `bool` | `True` | 启用从收件箱检索最新电子邮件 |
| `get_emails_from_user`  | `bool` | `True` | 启用从特定发件人获取电子邮件 |
| `get_unread_emails`     | `bool` | `True` | 启用获取未读电子邮件     |
| `get_starred_emails`    | `bool` | `True` | 启用检索已加星标的电子邮件  |
| `get_emails_by_context` | `bool` | `True` | 启用通过上下文搜索电子邮件  |
| `get_emails_by_date`    | `bool` | `True` | 启用在日期范围内检索电子邮件 |
| `create_draft_email`    | `bool` | `True` | 启用创建电子邮件草稿     |
| `send_email`            | `bool` | `True` | 启用立即发送电子邮件     |
| `search_emails`         | `bool` | `True` | 启用搜索电子邮件       |

## 工具包函数

| 函数                      | 描述                |
| ----------------------- | ----------------- |
| `get_latest_emails`     | 从用户收件箱获取最新的 X 封邮件 |
| `get_emails_from_user`  | 从特定发件人获取 X 封邮件    |
| `get_unread_emails`     | 获取最新的 X 封未读邮件     |
| `get_starred_emails`    | 获取 X 封已加星标的邮件     |
| `get_emails_by_context` | 获取匹配特定上下文的 X 封邮件  |
| `get_emails_by_date`    | 在特定日期范围内获取邮件      |
| `create_draft_email`    | 创建并保存电子邮件草稿       |
| `send_email`            | 立即发送电子邮件          |
| `search_emails`         | 使用自然语言查询搜索电子邮件    |

## 开发者资源

* 查看 [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/gmail.py)
* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/tools/gmail_tools.py)
