Skip to content

Cherzing/Mail-Auto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mail-Auto

自动化邮件发送工具,支持模板、批量发送、定时调度、失败重试。

安装

pip install -r requirements.txt

配置

cp 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!"

批量发送(CSV 收件人)

准备 recipients.csv

email,name,title
alice@example.com,Alice,Welcome
bob@example.com,Bob,Hello
python -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 中的列名(除 emailname 外)会自动作为模板变量。

日志

日志输出到控制台和 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

About

自动化邮件发送工具,支持模板、批量发送、定时调度、失败重试

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors