From 9e761140c19d546eaecd82d713ace98bdc55196b Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Sat, 13 Dec 2025 04:01:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SMTP=E9=85=8D=E9=A2=9D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=87=8D=E7=BD=AE=EF=BC=88=E5=8C=97=E4=BA=AC=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=87=8C=E6=99=A80=E7=82=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加reset_smtp_daily_quota函数主动重置配额 - 添加定时任务在北京时间00:00自动重置SMTP配额 - 保留被动重置作为备份机制 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app.py | 5 +++++ email_service.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app.py b/app.py index 9651046..99edf5b 100755 --- a/app.py +++ b/app.py @@ -4017,10 +4017,15 @@ def scheduled_task_worker(): # 每小时清理过期验证码 schedule.every().hour.do(cleanup_expired_captcha) + # 每天北京时间0点重置SMTP配额 + quota_reset_utc_time = cst_to_utc_time("00:00") + schedule.every().day.at(quota_reset_utc_time).do(email_service.reset_smtp_daily_quota) + # 只在首次运行时打印基础任务日志 if is_first_run: print(f"[定时任务] 已设置数据清理任务: 每天 CST 03:00 (UTC {cleanup_utc_time})") print(f"[定时任务] 已设置验证码清理任务: 每小时执行一次") + print(f"[定时任务] 已设置SMTP配额重置: 每天 CST 00:00 (UTC {quota_reset_utc_time})") # 如果启用了定时浏览任务,则添加 if config.get('schedule_enabled'): diff --git a/email_service.py b/email_service.py index 892de8a..4e2708f 100644 --- a/email_service.py +++ b/email_service.py @@ -933,6 +933,23 @@ def _update_email_stats(email_type: str, success: bool): conn.commit() +def reset_smtp_daily_quota(): + """重置所有SMTP配置的每日发送计数(北京时间凌晨0点调用)""" + today = get_beijing_today() + with db_pool.get_db() as conn: + cursor = conn.cursor() + cursor.execute(""" + UPDATE smtp_configs + SET daily_sent = 0, daily_reset_date = ? + WHERE daily_reset_date != ? OR daily_reset_date IS NULL OR daily_reset_date = '' + """, (today, today)) + updated = cursor.rowcount + conn.commit() + if updated > 0: + print(f"[邮件服务] 已重置 {updated} 个SMTP配置的每日配额") + return updated + + def get_email_stats() -> Dict[str, Any]: """获取邮件统计""" with db_pool.get_db() as conn: