import logging import base64 import os import resend from config import settings logger = logging.getLogger(__name__) # Embed logo as base64 so it works in any email client without a public URL _LOGO_PATH = os.path.join(os.path.dirname(__file__), "assets", "bell_systems_horizontal_darkMode.png") try: with open(_LOGO_PATH, "rb") as _f: _LOGO_B64 = base64.b64encode(_f.read()).decode() _LOGO_SRC = f"data:image/png;base64,{_LOGO_B64}" except Exception: _LOGO_SRC = "" # fallback: image won't appear but email still sends def send_email(to: str, subject: str, html: str) -> None: """Send a transactional email via Resend.""" try: resend.api_key = settings.resend_api_key resend.Emails.send({ "from": settings.email_from, "to": to, "subject": subject, "html": html, }) logger.info("Email sent to %s — subject: %s", to, subject) except Exception as exc: logger.error("Failed to send email to %s: %s", to, exc) raise def send_device_manufactured_email( customer_email: str, serial_number: str, device_name: str, customer_name: str | None = None, ) -> None: """ Notify a customer that their BellSystems device has been manufactured and is being prepared for shipment. """ greeting = f"Dear {customer_name}," if customer_name else "Dear valued customer," html = f"""