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""" Your BellSystems Device Has Been Manufactured
{"BellSystems" if _LOGO_SRC else "

BELLSYSTEMS

"}

Manufacturing Update

{greeting}

We are pleased to inform you that your BellSystems {device_name} has been successfully manufactured and has passed all quality checks.

Your device is now being prepared for delivery. You will receive a separate notification with tracking information once it has been dispatched.

Device Model
BellSystems {device_name}
Serial Number
{serial_number}

Thank you for choosing BellSystems. We take great pride in crafting each device with care and precision, and we look forward to delivering an exceptional experience to you.

BellSystems.gr

Questions? Contact us at support@bellsystems.gr

If you did not expect this notification, please disregard this message.

""" send_email( to=customer_email, subject=f"Your BellSystems {device_name} has been manufactured", html=html, )