Files
photobooth/backend/mailer.py
Jules c8e4ec80c1 Init photobooth - borne photo evenementielle RPi4
Backend FastAPI complet : camera gphoto2, filtres/overlays Pillow,
chroma key OpenCV, multi-shot/collage, GIF, impression CUPS, email SMTP,
QR code. Frontend web vanilla (HTML/CSS/JS) pour Chromium kiosk.
Menu admin cache (appui long coin ecran). Toutes les fonctionnalites
activables/desactivables. Scripts install + systemd pour RPi4.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 21:46:31 +01:00

65 lines
2.1 KiB
Python

import logging
import smtplib
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email import encoders
from pathlib import Path
from backend.config import charger_config
log = logging.getLogger("photobooth.mailer")
def envoyer_photo(destinataire: str, chemin_photo: Path) -> bool:
"""Envoie une photo par email."""
config = charger_config()
conf_email = config.get("email", {})
conf_event = config.get("evenement", {})
smtp_host = conf_email.get("smtp_host", "")
smtp_port = conf_email.get("smtp_port", 587)
smtp_user = conf_email.get("smtp_user", "")
smtp_password = conf_email.get("smtp_password", "")
expediteur = conf_email.get("expediteur", smtp_user)
if not smtp_host or not smtp_user:
log.error("Configuration email incomplete")
return False
sujet = conf_email.get("sujet", "Votre photo - {evenement}").format(
evenement=conf_event.get("nom", "Photobooth")
)
message = conf_email.get("message", "Voici votre photo !").format(
evenement=conf_event.get("nom", "Photobooth")
)
msg = MIMEMultipart()
msg["From"] = expediteur
msg["To"] = destinataire
msg["Subject"] = sujet
msg.attach(MIMEText(message, "plain", "utf-8"))
# Piece jointe
if chemin_photo.exists():
with open(chemin_photo, "rb") as f:
piece = MIMEBase("image", "jpeg")
piece.set_payload(f.read())
encoders.encode_base64(piece)
piece.add_header(
"Content-Disposition",
f"attachment; filename={chemin_photo.name}"
)
msg.attach(piece)
try:
with smtplib.SMTP(smtp_host, smtp_port, timeout=10) as serveur:
serveur.starttls()
serveur.login(smtp_user, smtp_password)
serveur.send_message(msg)
log.info(f"Email envoye a {destinataire}")
return True
except (smtplib.SMTPException, OSError) as e:
log.error(f"Erreur envoi email : {e}")
return False