# 找回密码邮件脚本 扫描 `password_reset_requests` 表中状态为 `pending` 的工单,生成随机新密码、更新用户表、并通过网易 126 邮箱将新密码发送给用户。 ## 配置 1. 复制 `config.ini.example` 为 `config.ini`。 2. 在 `config.ini` 中填写: - **[email]** 发件人邮箱、SMTP 服务器(smtp.126.com:465)。**126 邮箱要求**:`smtp_user` 填**完整邮箱**(如 `xxx@126.com`),`smtp_password` 填**授权码**(非登录密码,在 126 网页版 设置 → POP3/SMTP/IMAP 中开启服务并生成)。 - **[database]** 与 backend-client 相同的 MySQL 连接信息。 ## 运行 ```bash pip install -r requirements.txt python send_reset_password.py ``` 脚本会每 60 秒(可在 `[script] scan_interval_seconds` 中修改)扫描一次数据库,只处理 **created_at > 配置中 last_scan_time** 的 `pending` 工单;每轮结束后将当前时间写回 `config.ini` 的 `last_scan_time`,这样重启后也不会漏单。 ## 数据库 需先执行 backend-client 的迁移: - `backend-client/migrations/20260216_create_password_reset_requests.sql` 创建表 `password_reset_requests` 后,脚本才能正常扫描。