feat: 添加邮件功能第四阶段 - 任务完成通知
1. 添加任务完成邮件模板 (templates/email/task_complete.html) 2. 在email_service.py中添加: - task_notify_enabled 字段支持 - send_task_complete_email() 函数,支持附件大小限制和分批发送 - send_task_complete_email_async() 异步发送函数 - MAX_ATTACHMENT_SIZE 常量 (10MB) 3. 更新app.py: - 邮件设置API支持task_notify_enabled字段 - 截图回调中集成任务完成邮件发送 4. 更新admin.html: - 添加"启用任务完成通知"开关 - 更新loadEmailSettings/updateEmailSettings函数 附件超过10MB时会自动分两封邮件发送(通知+截图),作为容错机制 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
31
app.py
31
app.py
@@ -2487,11 +2487,11 @@ def take_screenshot_for_account(user_id, account_id, browse_type="应读", sourc
|
||||
# 重置账号状态
|
||||
account.is_running = False
|
||||
account.status = "未开始"
|
||||
|
||||
|
||||
# 先清除任务状态(这样to_dict()不会包含detail_status)
|
||||
if account_id in task_status:
|
||||
del task_status[account_id]
|
||||
|
||||
|
||||
# 然后发送更新
|
||||
socketio.emit('account_update', account.to_dict(), room=f'user_{user_id}')
|
||||
|
||||
@@ -2517,6 +2517,29 @@ def take_screenshot_for_account(user_id, account_id, browse_type="应读", sourc
|
||||
source=source
|
||||
)
|
||||
|
||||
# 发送任务完成邮件通知
|
||||
try:
|
||||
user_info = database.get_user_by_id(user_id)
|
||||
if user_info and user_info.get('email'):
|
||||
screenshot_path = None
|
||||
if result and result.get('success') and result.get('filename'):
|
||||
screenshot_path = os.path.join(SCREENSHOTS_DIR, result['filename'])
|
||||
|
||||
account_name = account.remark if account.remark else account.username
|
||||
email_service.send_task_complete_email_async(
|
||||
user_id=user_id,
|
||||
email=user_info['email'],
|
||||
username=user_info['username'],
|
||||
account_name=account_name,
|
||||
browse_type=browse_type,
|
||||
total_items=browse_result.get('total_items', 0),
|
||||
total_attachments=browse_result.get('total_attachments', 0),
|
||||
screenshot_path=screenshot_path,
|
||||
log_callback=lambda msg: log_to_client(msg, user_id, account_id)
|
||||
)
|
||||
except Exception as email_error:
|
||||
logger.warning(f"发送任务完成邮件失败: {email_error}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"截图回调出错: {e}")
|
||||
|
||||
@@ -3716,12 +3739,14 @@ def update_email_settings_api():
|
||||
failover_enabled = data.get('failover_enabled', True)
|
||||
register_verify_enabled = data.get('register_verify_enabled')
|
||||
base_url = data.get('base_url')
|
||||
task_notify_enabled = data.get('task_notify_enabled')
|
||||
|
||||
email_service.update_email_settings(
|
||||
enabled=enabled,
|
||||
failover_enabled=failover_enabled,
|
||||
register_verify_enabled=register_verify_enabled,
|
||||
base_url=base_url
|
||||
base_url=base_url,
|
||||
task_notify_enabled=task_notify_enabled
|
||||
)
|
||||
return jsonify({'success': True})
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user