Skip to content
Back to skills

Email Automation

ASecurity

邮箱自动化:读取、搜索、草拟和发送邮件,支持 Gmail API 以及通用 IMAP/SMTP 流程。

  • 92 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 22, 2026
ai-agentspythongobashapisecurity

Works with

  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 4 files and shows the line behind each finding

Scanned September 22, 2026

npx -y skills add aAAaqwq/AGI-Super-Team --skill email-automation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Email Automation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Email Automation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aaaaqwq-email-automation-agi-super-team/badge)](https://www.skillsdirectory.com/skills/aaaaqwq-email-automation-agi-super-team)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: email-automation
description: 邮箱自动化:读取、搜索、草拟和发送邮件,支持 Gmail API 以及通用 IMAP/SMTP 流程。
author: Daniel Li
---

# Email Automation Skill

- Author: Daniel Li
- Copyright © Daniel Li. All rights reserved.

邮箱自动化:读取、搜索、草拟、发送邮件。

## 支持的方式

### 方式 1: Gmail API (推荐)

**优点**: 功能完整,支持标签、搜索、草稿
**配置步骤**:

1. 访问 [Google Cloud Console](https://console.cloud.google.com/)
2. 创建项目 → 启用 Gmail API
3. 创建 OAuth 2.0 凭据(桌面应用)
4. 下载 `credentials.json`
5. 存储到 `~/.config/gmail/credentials.json`

```bash
# 安装依赖
pip3 install google-auth-oauthlib google-api-python-client

# 首次授权(会打开浏览器)
python3 ~/clawd/skills/email-automation/gmail_auth.py
```

### 方式 2: IMAP/SMTP (通用)

**优点**: 支持任何邮箱
**配置**:

```bash
# 存储凭据
pass insert email/gmail-address    # 邮箱地址
pass insert email/gmail-app-pass   # 应用专用密码(非登录密码)
```

Gmail 应用专用密码获取:
1. 访问 https://myaccount.google.com/apppasswords
2. 选择"邮件" + "其他设备"
3. 生成 16 位密码

### 方式 3: n8n 工作流

使用 n8n 的 Gmail/IMAP 节点,通过 webhook 触发。

---

## 核心功能

### 读取邮件

```python
# gmail_read.py
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials

creds = Credentials.from_authorized_user_file('token.json')
service = build('gmail', 'v1', credentials=creds)

# 获取最新 10 封邮件
results = service.users().messages().list(
    userId='me', maxResults=10, q='is:unread'
).execute()

for msg in results.get('messages', []):
    detail = service.users().messages().get(
        userId='me', id=msg['id'], format='metadata'
    ).execute()
    headers = {h['name']: h['value'] for h in detail['payload']['headers']}
    print(f"From: {headers.get('From')}")
    print(f"Subject: {headers.get('Subject')}")
    print("---")
```

### 搜索邮件

```python
# Gmail 搜索语法
queries = {
    "未读": "is:unread",
    "今天": "newer_than:1d",
    "重要": "is:important",
    "带附件": "has:attachment",
    "来自某人": "from:someone@example.com",
    "主题包含": "subject:关键词",
}
```

### 发送邮件

```python
# gmail_send.py
import base64
from email.mime.text import MIMEText

def create_message(to, subject, body):
    message = MIMEText(body)
    message['to'] = to
    message['subject'] = subject
    raw = base64.urlsafe_b64encode(message.as_bytes()).decode()
    return {'raw': raw}

def send_email(service, to, subject, body):
    message = create_message(to, subject, body)
    service.users().messages().send(userId='me', body=message).execute()
```

### IMAP 方式(备选)

```python
import imaplib
import email

# 连接
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(EMAIL, APP_PASSWORD)
mail.select('inbox')

# 搜索未读
status, messages = mail.search(None, 'UNSEEN')
for num in messages[0].split():
    status, data = mail.fetch(num, '(RFC822)')
    msg = email.message_from_bytes(data[0][1])
    print(f"From: {msg['from']}")
    print(f"Subject: {msg['subject']}")
```

---

## 安全策略

### 权限分层(参考 SECURITY.md)

| 操作 | 权限级别 |
|------|----------|
| 读取邮件列表 | 🟢 自由 |
| 读取邮件内容 | 🟢 自由 |
| 搜索邮件 | 🟢 自由 |
| 创建草稿 | 🟢 自由 |
| 发送邮件 | 🟡 需确认 |
| 删除邮件 | 🟡 需确认 |
| 修改标签 | 🟢 自由 |

### 发送确认流程

```
⚠️ 需要确认发送邮件:

收件人: xxx@example.com
主题: Re: 关于项目进度
内容预览:
---
你好,

关于项目进度...
---

回复 "确认" 发送,或 "取消" 放弃
```

---

## 自动化场景

### 1. 邮件摘要(每日)

```
每天早上检查未读邮件,生成摘要推送到 Telegram
```

### 2. 重要邮件提醒

```
监控特定发件人/关键词,立即通知
```

### 3. 自动回复草稿

```
收到邮件后自动生成回复草稿,等待确认后发送
```

---

## 配置清单

完成配置后,在 TOOLS.md 中记录:

```markdown
### Email
- Provider: Gmail
- Address: xxx@gmail.com
- Auth: OAuth 2.0 / App Password
- Token: ~/.config/gmail/token.json
- 权限: 读取 ✅ | 发送 ⚠️需确认
```

---

## 相关文件

- `gmail_auth.py` - OAuth 授权脚本
- `gmail_read.py` - 读取邮件
- `gmail_send.py` - 发送邮件
- `SECURITY.md` - 安全策略

Files in this skill

  • SKILL.md4.5 KB
  • gmail_auth.py2.2 KB
  • gmail_read.py3.1 KB
  • gmail_send.py2.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.