← Back to Skills Marketplace
38
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install laosi-email-helper
Description
邮件助手 - 编写/发送/管理邮件,支持SMTP发信和IMAP收信,多模板草稿,自动归档
README (SKILL.md)
Email Helper - 邮件助手
激活词: 邮件 / 发邮件 / email
功能
- 编写邮件草稿(支持模板)
- 通过SMTP发送邮件
- 通过IMAP读取收件箱
- 邮件归档和搜索
- 草稿本地持久化
Python 实现
import os, json, smtplib, imaplib, email
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from datetime import datetime
from typing import List, Optional
DRAFT_FILE = os.path.join(os.path.dirname(__file__), "email_drafts.json")
class EmailHelper:
def __init__(self):
os.makedirs(os.path.dirname(DRAFT_FILE), exist_ok=True)
self.drafts = self._load_drafts()
def _load_drafts(self) -> list:
if os.path.exists(DRAFT_FILE):
with open(DRAFT_FILE, encoding="utf-8") as f:
return json.load(f)
return []
def _save_drafts(self):
with open(DRAFT_FILE, "w", encoding="utf-8") as f:
json.dump(self.drafts, f, ensure_ascii=False, indent=2)
def create_draft(self, to_addr: str, subject: str, body: str,
cc: str = "", bcc: str = "") -> dict:
"""创建邮件草稿"""
draft = {
"id": len(self.drafts) + 1,
"to": to_addr,
"cc": cc,
"bcc": bcc,
"subject": subject,
"body": body,
"status": "draft",
"created": datetime.now().isoformat(),
}
self.drafts.append(draft)
self._save_drafts()
return draft
def build_mime(self, draft_id: int) -> Optional[MIMEMultipart]:
"""将草稿构建为MIME消息"""
draft = next((d for d in self.drafts if d["id"] == draft_id), None)
if not draft:
return None
msg = MIMEMultipart()
msg["From"] = draft.get("from_addr", "[email protected]")
msg["To"] = draft["to"]
if draft.get("cc"):
msg["Cc"] = draft["cc"]
msg["Subject"] = draft["subject"]
msg.attach(MIMEText(draft["body"], "plain", "utf-8"))
return msg
def send(self, draft_id: int, smtp_host: str, smtp_port: int,
username: str, password: str, use_tls: bool = True) -> dict:
"""通过SMTP发送草稿"""
draft = next((d for d in self.drafts if d["id"] == draft_id), None)
if not draft:
return {"error": f"Draft #{draft_id} not found"}
msg = self.build_mime(draft_id)
if not msg:
return {"error": "Failed to build MIME message"}
try:
server = smtplib.SMTP(smtp_host, smtp_port, timeout=10)
if use_tls:
server.starttls()
server.login(username, password)
server.send_message(msg)
server.quit()
draft["status"] = "sent"
draft["sent_at"] = datetime.now().isoformat()
self._save_drafts()
return {"success": True, "to": draft["to"], "subject": draft["subject"]}
except Exception as e:
return {"error": str(e)}
def inbox(self, imap_host: str, username: str, password: str,
limit: int = 10) -> List[dict]:
"""读取收件箱"""
try:
conn = imaplib.IMAP4_SSL(imap_host)
conn.login(username, password)
conn.select("INBOX")
_, data = conn.search(None, "ALL")
ids = data[0].split()[-limit:] # 最近的N封
messages = []
for mid in ids:
_, msg_data = conn.fetch(mid, "(RFC822)")
raw = email.message_from_bytes(msg_data[0][1])
messages.append({
"from": raw["From"],
"subject": raw["Subject"],
"date": raw["Date"],
"body": self._get_text(raw)[:200],
})
conn.logout()
return messages
except Exception as e:
return [{"error": str(e)}]
def _get_text(self, msg) -> str:
"""从邮件对象提取正文"""
if msg.is_multipart():
for part in msg.walk():
if part.get_content_type() == "text/plain":
return part.get_payload(decode=True).decode("utf-8", errors="ignore")
return msg.get_payload(decode=True).decode("utf-8", errors="ignore") if msg.get_payload(decode=True) else ""
def list_drafts(self, status: str = None) -> list:
"""列出草稿"""
if status:
return [d for d in self.drafts if d["status"] == status]
return self.drafts
def delete_draft(self, draft_id: int) -> bool:
"""删除草稿"""
before = len(self.drafts)
self.drafts = [d for d in self.drafts if d["id"] != draft_id]
if len(self.drafts) \x3C before:
self._save_drafts()
return True
return False
# 使用示例
eh = EmailHelper()
# 创建草稿
draft = eh.create_draft(
to_addr="[email protected]",
subject="Weekly Update - May 28",
body="Hi team,\
\
This week's update:\
1. Feature A completed\
2. Bug fixes deployed\
\
Best,\
Laosi"
)
print(f"Draft #{draft['id']}: {draft['subject']}")
# 列出所有草稿
for d in eh.list_drafts():
print(f" [{d['status']}] #{d['id']}: {d['subject']} -> {d['to']}")
# 实际发送(需要配置SMTP)
# result = eh.send(1, "smtp.gmail.com", 587, "[email protected]", "app_password")
# print(f"Send result: {result}")
邮件模板
TEMPLATES = {
"weekly_report": {
"subject": "Weekly Report - {date}",
"body": "Hi {name},\
\
{content}\
\
Best,\
{sender}"
},
"meeting_invite": {
"subject": "Meeting: {topic} - {date}",
"body": "Hi {name},\
\
You're invited to {topic} at {time}.\
\
Agenda:\
{agenda}\
\
Regards,\
{sender}"
},
"follow_up": {
"subject": "Re: {topic}",
"body": "Hi {name},\
\
Following up on {topic}. Any updates?\
\
Best,\
{sender}"
}
}
使用场景
- 周报自动发送: 集成数据分析结果,自动生成并发送周报
- 告警通知: 系统异常时自动发邮件给值班人员
- 批量邀请: 会议邀请/活动通知批量发送
- 邮件归档: 按项目/关键词自动分类归档邮件
配置
smtp:
host: smtp.gmail.com
port: 587
use_tls: true
imap:
host: imap.gmail.com
sender:
name: AI Assistant
email: [email protected]
依赖
- Python 3.8+
- 标准库(smtplib, imaplib, email)
Usage Guidance
Install only if you are comfortable using an agent for email workflows. Use app-specific or scoped mail credentials where possible, review recipients and message bodies before sending, and remember that saved drafts may contain private email content on disk.
Capability Assessment
Purpose & Capability
The SMTP sending, IMAP inbox reading, templates, draft management, and local persistence all align with the stated email-helper purpose.
Instruction Scope
The activation phrases are broad and the skill lacks an explicit confirmation rule before sending mail or reading inbox data, so users should invoke it deliberately and confirm sensitive actions.
Install Mechanism
The artifact is a single SKILL.md with embedded example Python code and no install scripts, package dependencies, or automatic execution mechanism.
Credentials
Network access to user-specified SMTP and IMAP servers is proportionate for an email helper, but mailbox credentials and message contents are sensitive.
Persistence & Privilege
Drafts are saved to a local email_drafts.json file in the skill directory; this is disclosed as local draft persistence, though privacy/retention guidance is minimal.
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install laosi-email-helper - After installation, invoke the skill by name or use
/laosi-email-helper - Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
- Initial release of the Email Helper skill.
- Compose, send (SMTP), and manage drafts with template support.
- Read inbox emails via IMAP.
- Features auto-archiving, draft persistence, and email search.
- Provides ready-to-use templates for common scenarios (weekly report, meeting invite, follow-up).
- Designed for productivity and automation of email tasks.
Metadata
Frequently Asked Questions
What is 邮件助手?
邮件助手 - 编写/发送/管理邮件,支持SMTP发信和IMAP收信,多模板草稿,自动归档. It is an AI Agent Skill for Claude Code / OpenClaw, with 38 downloads so far.
How do I install 邮件助手?
Run "/install laosi-email-helper" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is 邮件助手 free?
Yes, 邮件助手 is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does 邮件助手 support?
邮件助手 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created 邮件助手?
It is built and maintained by 534422530 (@534422530); the current version is v1.0.0.
More Skills