"""Welcome message delivered to a newly activated mailbox.""" from __future__ import annotations import logging from sqlalchemy.ext.asyncio import AsyncSession from app.config import get_settings from app.models import Account from app.services.domain_provisioning import get_domain_by_name from app.services.email_templates import BRAND_NAME, build_welcome_email from app.services.mail_sender import deliver_email logger = logging.getLogger(__name__) NOTIFICATIONS_FROM_LOCAL = "notifications" async def send_welcome_email(session: AsyncSession, account: Account) -> None: settings = get_settings() platform_domain = await get_domain_by_name(session, settings.platform_domain) if platform_domain is None: raise ValueError("Platform mail domain is not configured.") login_url = f"https://{settings.app_public_host}/login" organization = account.company_domain if account.account_type == "company" else None subject, body_text, body_html = build_welcome_email( first_name=account.first_name, work_email=account.email, organization=organization, login_url=login_url, is_company_account=account.account_type == "company", ) sender = f"AGMail Team <{NOTIFICATIONS_FROM_LOCAL}@{settings.platform_domain}>" await deliver_email( sender=sender, recipients=[account.email], cc=[], bcc=[], subject=subject, body_text=body_text, body_html=body_html, domain=platform_domain, )