自动化邮件发送工具,支持模板、批量发送、定时调度、失败重试。
pip install -r requirements.txtcp config.example.yaml config.yaml
# 编辑 config.yaml 填入你的 SMTP 配置密码支持环境变量引用:
password: "${MAIL_PASSWORD}"export MAIL_PASSWORD="your-password"python -m mail_auto send --to user@example.com --subject "Hello" --body "Hi there!"python -m mail_auto send --template default.html --to user@example.com \
--subject "Welcome" --template-var "name=Alice" --template-var "title=Welcome!"准备 recipients.csv:
email,name,title
alice@example.com,Alice,Welcome
bob@example.com,Bob,Hellopython -m mail_auto send --template default.html --recipients recipients.csv \
--subject "Newsletter" --template-var "message=This week's update"python -m mail_auto send --to user@example.com --subject "Report" \
--body "See attached." --attachment report.pdf --attachment data.xlsx# Cron 表达式(工作日每天 9:00)
python -m mail_auto schedule --cron "0 9 * * 1-5" \
--template default.html --recipients recipients.csv --subject "Daily Report"
# 间隔发送(每 3600 秒)
python -m mail_auto schedule --interval 3600 \
--template default.html --recipients recipients.csv --subject "Hourly Update"
# 延迟发送(60 秒后)
python -m mail_auto schedule --delay 60 \
--template default.html --recipients recipients.csv --subject "Delayed"python -m mail_auto --config /path/to/config.yaml send ...模板使用 Jinja2 语法,放在 templates/ 目录下:
<p>Hello {{ name }},</p>
<p>{{ message }}</p>CSV 中的列名(除 email 和 name 外)会自动作为模板变量。
日志输出到控制台和 logs/mail_auto.log(按日期轮转,保留 30 天)。
Mail-Auto/
├── mail_auto/
│ ├── __main__.py # CLI 入口
│ ├── config.py # 配置管理
│ ├── mailer.py # SMTP 发送
│ ├── template.py # Jinja2 模板
│ ├── queue.py # 发送队列 + 重试
│ ├── scheduler.py # 定时调度
│ ├── logger.py # 日志
│ └── models.py # 数据模型
├── templates/ # 邮件模板
├── config.example.yaml # 配置示例
└── requirements.txt