🔒 Repository is read-only – file editing is disabled.

PaganLinux/pagan-web-v2/mail.py main

26 linii Raw ← Powrót
1234567891011121314151617181920212223242526
"""Wysyłka e-mail przez SMTP."""
import smtplib, logging
from email.mime.text import MIMEText
from config.settings import SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, MAIL_FROM

_log = logging.getLogger("mail")

def send_email(to_addr: str, subject: str, body: str) -> bool:
    """Wyślij e-mail. Zwraca True/False."""
    if not SMTP_PASS:
        _log.warning("SMTP_PASS not set – email not sent")
        return False
    msg = MIMEText(body, "plain", "utf-8")
    msg["Subject"] = subject
    msg["From"] = MAIL_FROM
    msg["To"] = to_addr
    try:
        with smtplib.SMTP(SMTP_HOST, SMTP_PORT, timeout=15) as s:
            s.starttls()
            s.login(SMTP_USER, SMTP_PASS)
            s.send_message(msg)
        _log.info(f"Email sent to {to_addr}: {subject}")
        return True
    except Exception as e:
        _log.error(f"Email to {to_addr} failed: {e}")
        return False