Email Operations

👤 yiweiweilai 📦 v2.0.1 ⭐ 4.4 ⬇️ 651 下載
📄 辦公效率 免費 🔑 需 API Key

📖 技能介紹


name: email-operations description: | 郵件操作技能,通過 SMTP/IMAP 協議讀取和傳送郵件。當用戶想要檢視郵件、搜尋郵件內容、 獲取收件箱列表、拉取特定郵件詳情、傳送郵件、或需要與郵箱服務互動時,使用此技能。 無論使用者是否明確提到 "IMAP" 或 "SMTP",只要涉及郵件收發操作,均可觸發此技能。 適用場景:檢視收件箱、搜尋郵件、按條件過濾、獲取郵件正文和附件資訊、傳送郵件、群發郵件等。 version: 2.0.0


Email Operations Skill

通過 SMTP/IMAP 協議讀取和管理郵件的技能,支援郵件收發全流程操作。

憑證配置

重要:憑證儲存在技能目錄下的 .env 檔案中,而非系統環境變數。

使用此技能前,請先配置 skills/email-operations/.env 檔案:

# 郵箱基礎配置
EMAIL_ADDRESS=your@email.com
EMAIL_IMAP_PASSWORD=your_imap_password
EMAIL_SMTP_PASSWORD=your_smtp_password

# IMAP 伺服器配置(可選,有預設值)
EMAIL_IMAP_HOST=imap.gmail.com
EMAIL_IMAP_PORT=993

# SMTP 伺服器配置(可選,有預設值)
EMAIL_SMTP_HOST=smtp.gmail.com
EMAIL_SMTP_PORT=587
EMAIL_SMTP_SSL=false

常用郵件服務配置

Gmail:

EMAIL_ADDRESS=your@gmail.com
EMAIL_IMAP_HOST=imap.gmail.com
EMAIL_IMAP_PORT=993
EMAIL_SMTP_HOST=smtp.gmail.com
EMAIL_SMTP_PORT=587

注意:需要開啟"應用專用密碼"

QQ/foxmail:

EMAIL_ADDRESS=your@qq.com
EMAIL_IMAP_HOST=imap.qq.com
EMAIL_IMAP_PORT=993
EMAIL_SMTP_HOST=smtp.qq.com
EMAIL_SMTP_PORT=587
EMAIL_SMTP_SSL=false

163/188:

EMAIL_ADDRESS=your@163.com
EMAIL_IMAP_HOST=imap.163.com
EMAIL_IMAP_PORT=993
EMAIL_SMTP_HOST=smtp.163.com
EMAIL_SMTP_PORT=465
EMAIL_SMTP_SSL=true

Outlook:

EMAIL_ADDRESS=your@outlook.com
EMAIL_IMAP_HOST=outlook.office365.com
EMAIL_IMAP_PORT=993
EMAIL_SMTP_HOST=smtp.office365.com
EMAIL_SMTP_PORT=587

核心功能

讀取郵件

功能 方法 說明
獲取收件箱 get_inbox() 返回郵件列表摘要
獲取詳情 get_email() 返回完整郵件內容
搜尋郵件 search_emails() 按關鍵詞/發件人/日期搜尋
儲存附件 save_attachment() 下載附件到本地
資料夾列表 get_folders() 獲取郵箱資料夾

傳送郵件

功能 方法 說明
傳送文本郵件 send_email() 傳送純文本郵件
傳送HTML郵件 send_html_email() 傳送 HTML 格式郵件
傳送帶附件 send_email_with_attachments() 新增附件傳送

使用示例

讀取郵件

from scripts.email_client import EmailClient

client = EmailClient()

# 獲取收件箱郵件列表
emails = client.get_inbox(count=10)
for email in emails:
    print(f"主題: {email['subject']}")
    print(f"發件人: {email['from']}")
    print(f"時間: {email['date']}")
    print("---")

# 按 UID 獲取郵件詳情
email = client.get_email(uid=123)
print(f"正文: {email['body']['plain']}")
print(f"附件: {email['attachments']}")

# 搜尋郵件
results = client.search_emails(
    keyword="發票",
    from_addr="zhangsan@company.com",
    date_from="2024-01-01",
    date_to="2024-12-31"
)

傳送郵件

# 傳送文本郵件
client.send_email(
    to="recipient@example.com",
    subject="郵件主題",
    body="這是郵件正文內容"
)

# 傳送 HTML 郵件
client.send_html_email(
    to="recipient@example.com",
    subject="HTML 郵件",
    html_body="<h1>標題</h1><p>正文內容</p>"
)

# 傳送帶附件的郵件
client.send_email_with_attachments(
    to="recipient@example.com",
    subject="帶附件的郵件",
    body="請查收附件",
    attachments=[
        "./files/document.pdf",
        "./files/image.png"
    ]
)

# 群發郵件
recipients = ["user1@example.com", "user2@example.com", "user3@example.com"]
for recipient in recipients:
    client.send_email(
        to=recipient,
        subject="群發郵件",
        body="這是一封群發郵件"
    )

EmailClient 方法列表

讀取操作

方法 說明 引數
get_inbox() 獲取收件箱郵件列表 count=10, offset=0, folder="INBOX"
get_email() 獲取單封郵件詳情 uid, folder="INBOX"
search_emails() 搜尋郵件 keyword, from_addr, to_addr, date_from, date_to, folder
save_attachment() 儲存附件 email_uid, attachment_index, save_path
get_folders() 獲取資料夾列表

傳送操作

方法 說明 引數
send_email() 傳送文本郵件 to, subject, body, cc=None, bcc=None
send_html_email() 傳送HTML郵件 to, subject, html_body, cc=None, bcc=None
send_email_with_attachments() 傳送帶附件郵件 to, subject, body, attachments, cc, bcc

資料結構

訪問小蔥技能站7w4.net,解鎖更多實用的AI技能外掛。

郵件摘要 (get_inbox 返回)

{
    "uid": 12345,
    "subject": "郵件主題",
    "from": "sender@example.com",
    "from_name": "發件人姓名",
    "to": "recipient@example.com",
    "date": "2024-01-15 10:30:00",
    "size": 1024,
    "flags": ["已讀", "星標"],
    "is_read": True
}

郵件詳情 (get_email 返回)

{
    "uid": 12345,
    "subject": "郵件主題",
    "from": {"name": "發件人", "email": "sender@example.com"},
    "to": [{"name": "收件人", "email": "recipient@example.com"}],
    "date": "2024-01-15 10:30:00",
    "body": {
        "plain": "純文本內容",
        "html": "<html>...</html>"
    },
    "attachments": [
        {"index": 0, "name": "file.pdf", "size": 102400, "type": "application/pdf"}
    ],
    "headers": {"Message-ID": "...", "References": "..."}
}

命令列使用

# 列出收件箱郵件
python -m scripts.email_client --action list --count 10

# 檢視郵件詳情
python -m scripts.email_client --action show --uid 12345

# 搜尋郵件
python -m scripts.email_client --action search --keyword "發票"

# 檢視資料夾
python -m scripts.email_client --action folders

# 傳送測試郵件
python -m scripts.email_client --action send \
    --to "recipient@example.com" \
    --subject "測試郵件" \
    --body "這是測試郵件的內容"

# 從 UTF-8 檔案讀取正文後傳送,適合 Windows 下發送中文郵件
python -m scripts.email_client --action send \
    --to "recipient@example.com" \
    --subject "天氣簡報" \
    --body-file "./mail_body.txt"

# 傳送 HTML 檔案內容
python -m scripts.email_client --action send \
    --to "recipient@example.com" \
    --subject "HTML 郵件" \
    --html-body-file "./mail_body.html"

常見問題

Q: 認證失敗怎麼辦?

A: 請確保: 1. 郵箱地址正確 2. 使用的是"應用專用密碼"而非登入密碼(Gmail/QQ等) 3. IMAP 和 SMTP 服務已在郵箱設定中開啟

Q: 如何處理中文亂碼?

A: 指令碼已內建編碼檢測和轉換,會自動處理 GBK、UTF-8 等編碼。

Q: 附件大小有限制嗎?

A: 一般郵箱對附件大小有限制(Gmail 通常 25MB),請確保附件在此範圍內。

輸出格式示例

========================================
📧 收件箱 - 最新郵件
========================================

[1] 主題: 會議通知
    發件人: zhangsan@company.com
    時間: 2024-01-15 10:30:00
    狀態: 已讀

[2] 主題: 發票報銷
    發件人: finance@company.com
    時間: 2024-01-15 09:15:00
    狀態: 未讀 ⭐

========================================
共 2 封郵件
========================================

🤖 AI 評測

這個郵件技能做得相當不錯,功能覆蓋全面,從查郵件到發郵件都能搞定。文件寫得很詳細,配置說明清晰,還附帶多種常用郵箱的設定示例,新手也能快速上手。使用Python標準庫開發,不需要額外安裝依賴,穩定可靠。美中不足的是缺少自動化測試,對於重要功能來說不夠穩妥,另外錯誤提示資訊也可以更友好一些。總體而言,這是一個成熟度高、實用性強的郵件處理技能。

📊 多維度評分

適應性4.4
規範性4.2
有效性4.7
可靠性4.2
可信度4.9

📁 包含檔案 (6 個)

📄 .env 964 B
📄 SKILL.md 7.6 KB
📄 _meta.json 135 B
📄 evals/evals.json 1.3 KB
📄 requirements.txt 323 B
📄 scripts/email_client.py 32.4 KB