From cecec601e0920b094a8621253e8c8d4fefcb3692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=9A=D1=80=D0=B8=D0=B2?= =?UTF-8?q?=D0=BE=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Fri, 31 Jul 2026 01:16:29 +0700 Subject: [PATCH] fix: add debug logging to email alert function --- transcription_bot/handlers.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/transcription_bot/handlers.py b/transcription_bot/handlers.py index 7b1760a..cb3ddd6 100644 --- a/transcription_bot/handlers.py +++ b/transcription_bot/handlers.py @@ -34,7 +34,10 @@ def _transcription_log_and_notify_email(action: str, error_details: str): current_time = time.time() timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + logger.info(f"📧 [EMAIL ALERT] Attempting to send alert for: {action}") + if current_time - _last_transcription_email_time < 10.0: + logger.info(f"📧 [EMAIL ALERT] Cooldown active, skipping. Last: {_last_transcription_email_time}") return _last_transcription_email_time = current_time @@ -42,15 +45,29 @@ def _transcription_log_and_notify_email(action: str, error_details: str): import smtplib from email.mime.text import MIMEText msg = MIMEMultipart() - msg['From'] = str(getattr(config, 'DEFAULT_EMAIL_FROM', 'bot@noreply.com')) + + default_from = getattr(config, 'DEFAULT_EMAIL_FROM', 'bot@noreply.com') + smtp_server = getattr(config, 'SMTP_SERVER', 'localhost') + smtp_port = getattr(config, 'SMTP_PORT', 25) to_emails = getattr(config, 'ALERTS_SUPPORT_EMAILS', ['admin@example.com']) + + logger.info(f"📧 [EMAIL ALERT] From={default_from}, To={to_emails}, SMTP={smtp_server}:{smtp_port}") + + msg['From'] = str(default_from) msg['To'] = ', '.join(to_emails) if isinstance(to_emails, list) else str(to_emails) msg['Subject'] = f'TrueConf Bot Error: Транскрипция - {action}' body = f'Обнаружена ошибка в транскрипции.\nВремя: {timestamp}\nДействие: {action}\nДетали:\n{error_details}' msg.attach(MIMEText(body, 'plain', 'utf-8')) - with smtplib.SMTP(getattr(config, 'SMTP_SERVER', 'localhost'), int(getattr(config, 'SMTP_PORT', 25))) as server: + + logger.info(f"📧 [EMAIL ALERT] Connecting to SMTP...") + with smtplib.SMTP(smtp_server, int(smtp_port)) as server: + logger.info(f"📧 [EMAIL ALERT] Sending message...") server.send_message(msg) - except Exception: + logger.info(f"📧 [EMAIL ALERT] SUCCESS!") + except Exception as e: + logger.error(f"📧 [EMAIL ALERT] FAILED: {e}") + import traceback + logger.error(f"📧 [EMAIL ALERT] Traceback: {traceback.format_exc()}") pass import time @@ -164,3 +181,4 @@ async def transcription_handler(msg: Message): +