#!/usr/bin/env python3
"""Test mailer: sends 1 email via Brevo SMTP.

Use the credentials you supplied:
  BREVO_USER: b98ffc001@smtp-brevo.com
  BREVO_PASS: xsmtpsib-22ca12da6ff0... (shortened)

If it succeeds, you will see the email appear in the inbox.
"""

import csv
import os
import smtplib
import sys
from email.message import EmailMessage

BREVO_HOST = "smtp-relay.brevo.com"
BREVO_PORT = 587
BREVO_USER = os.environ.get("BREVO_USER")
BREVO_PASS = os.environ.get("BREVO_PASS")

if not BREVO_USER or not BREVO_PASS:
    print("BREVO_USER/BREVO_PASS not set", file=sys.stderr)
    sys.exit(1)

msg = EmailMessage()
msg['Subject'] = "Test Brevo SMTP"
msg['From'] = BREVO_USER
msg['To'] = BREVO_USER
msg.set_content("Ciao, questo è un email di test inviata da Brevo SMTP via Python.")

try:
    with smtplib.SMTP(BREVO_HOST, BREVO_PORT, timeout=30) as s:
        s.starttls()
        s.login(BREVO_USER, BREVO_PASS)
        s.send_message(msg)
    print("✅ Email inviata via Brevo SMTP")
except Exception as e:
    print("❌ Errore", e, file=sys.stderr)
    sys.exit(1)
