diff --git a/email_service.py b/email_service.py index ed67842..418a263 100644 --- a/email_service.py +++ b/email_service.py @@ -2,6 +2,7 @@ import logging import os +import re import smtplib import ssl from email.mime.multipart import MIMEMultipart @@ -36,37 +37,18 @@ def smtp_healthcheck() -> bool: def send_operator_digest(to_email: str, subject: str, html: str) -> bool: - """Дайджест оператору о новостях внешних источников (чекер ext_check). True при успехе.""" - if not SMTP_USER or not SMTP_PASS: - logger.warning("SMTP not configured, skipping operator digest to %s", to_email) - return False - if not to_email: - return False - msg = MIMEMultipart("alternative") - from email.header import Header - msg["Subject"] = subject - msg["From"] = f"{Header('Сметный ассистент', 'utf-8').encode()} <{SMTP_USER}>" - msg["To"] = to_email - msg.attach(MIMEText(html, "html", "utf-8")) - try: - context = ssl.create_default_context() - with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT, context=context, timeout=10) as server: - server.login(SMTP_USER, SMTP_PASS) - server.sendmail(SMTP_USER, to_email, msg.as_string()) - logger.info("Operator digest sent to %s", to_email) - return True - except Exception as e: # noqa: BLE001 - logger.error("Failed to send operator digest to %s: %s", to_email, e) - return False + """Сводка оператору о новостях внешних источников (чекер ext_check).""" + # Текстовая часть обязательна: без неё в клиентах с отключённым HTML письмо приходит + # пустым, и оператор не видит содержимого (находка ревью 08.09.2026). + text = re.sub(r"<[^>]+>", " ", html) + text = re.sub(r"\s+", " ", text).strip() or subject + return _send(to_email, subject, text, html) def send_verification_code(to_email: str, code: str) -> bool: - """Send 6-digit verification code to email. Returns True on success.""" - if not SMTP_USER or not SMTP_PASS: - logger.warning("SMTP not configured, skipping email to %s", to_email) - return False - + """Код подтверждения при регистрации.""" subject = "Код подтверждения — Сметный ИИ-ассистент" + text = f"Ваш код подтверждения: {code}\nДействителен 10 минут." html = f"""
Если вы не регистрировались — проигнорируйте это письмо.