Files
openclaw-config/workspace-resume/send_weekly_report.py
T
openclaw-314 ae4b7c8244 chore(workspace-resume): 配置清理与维护同步(2026-07-31)
- 精简 AGENTS.md 为中文版,新增核心职责声明
- MEMORY.md 补安全红线中文存档、抄送去除 wurd
- TOOLS.md 中文化,记录 IMAP 邮箱配置
- USER.md 团队同事去除 wurd
- send_weekly_report.py 硬编码密码迁移 .env、抄送去除吴睿东
- weekly-report-g5 SKILL.md 抄送去除 wurd
- 旧散装周报移入 .trash 回收站(可恢复)
- 新增 .trash 目录、memory/2026-07-31.md、2026-W31 周报

注:.env 已被 .gitignore 忽略,不包含密码
2026-07-31 10:30:57 +08:00

79 lines
2.4 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
G5 周报发送脚本
用法:构造多段邮件(纯文本 + HTML),存入钉邮草稿箱
"""
import email
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
import imaplib
import os
import time
import sys
def load_env(path):
"""读取 .env 文件,返回键值字典(标准库实现,无额外依赖)。"""
env = {}
try:
with open(path, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#') or '=' not in line:
continue
key, _, value = line.partition('=')
env[key.strip()] = value.strip().strip('"').strip("'")
except FileNotFoundError:
pass
return env
_ENV = load_env(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '.env'))
IMAP_HOST = 'imap.mxhichina.com'
IMAP_PORT = 993
IMAP_USER = _ENV.get('WITSOFT_IMAP_USER', 'yangxuan@witsoft.cn')
IMAP_PASSWORD = _ENV.get('WITSOFT_IMAP_PASSWORD', '')
def send_to_drafts(plain_body: str, html_body: str, date_range: str):
"""构造多段邮件并存入钉邮草稿箱"""
msg = MIMEMultipart('related')
msg['From'] = Header('杨轩', 'utf-8').encode() + ' <yangxuan@witsoft.cn>'
msg['To'] = Header('刘强', 'utf-8').encode() + ' <liuqiang@witsoft.cn>'
msg['Cc'] = (
Header('陈明', 'utf-8').encode() + ' <chenm@witsoft.cn>, '
+ Header('曾莉', 'utf-8').encode() + ' <zengli@witsoft.cn>'
)
msg['Subject'] = Header(f'G5开发周报 ({date_range})', 'utf-8').encode()
alt = MIMEMultipart('alternative')
alt.attach(MIMEText(plain_body, 'plain', 'utf-8'))
alt.attach(MIMEText(html_body, 'html', 'utf-8'))
msg.attach(alt)
raw_bytes = msg.as_bytes()
conn = imaplib.IMAP4_SSL(IMAP_HOST, IMAP_PORT)
conn.login(IMAP_USER, IMAP_PASSWORD)
drafts = '"&g0l6Pw-"'
result = conn.append(drafts, None, imaplib.Time2Internaldate(time.time()), raw_bytes)
conn.logout()
return result
if __name__ == '__main__':
# 测试
plain = """项目名称: 维云智造G5
主要任务: 测试
本周工作内容
周一(2026-07-13
- 测试
存在问题
无"""
html = "<p>test</p>"
result = send_to_drafts(plain, html, "2026-07-13 ~ 2026-07-17")
print(result)