"""HTML and plain-text templates for transactional email.""" from __future__ import annotations import html BRAND_NAME = "aGentic Email" BRAND_HANDLE = "@gentic.email" def _escape(value: str) -> str: return html.escape(value, quote=True) def build_employee_invitation_email( *, member_first_name: str, member_email: str, manager_name: str, manager_email: str, company_domain: str, login_url: str, initial_password: str, force_password_change: bool, ) -> tuple[str, str, str]: first_name = member_first_name.strip() or "there" organization = company_domain.strip() manager = manager_name.strip() or "Your administrator" manager_address = manager_email.strip() security_note = ( "For your security, you will be asked to create a new password " "immediately after your first sign-in." if force_password_change else ( "We recommend updating your password after your first sign-in " "from your account settings." ) ) subject = f"{manager} invited you to join {organization}" why_received = ( f"You are receiving this because {manager} invited you to a work email " f"account at {organization} on {BRAND_NAME}. It was sent to the personal " f"email address your administrator provided so you can complete your " f"first sign-in." ) unexpected_contact = ( f"If you were not expecting this invitation, please contact " f"{manager} at {manager_address}." if manager_address else "If you were not expecting this invitation, please contact your administrator." ) body_text = ( f"Hello {first_name},\n\n" f"{why_received}\n\n" f"Organization: {organization}\n" f"Work email address: {member_email}\n" f"Sign-in page: {login_url}\n\n" f"Sign-in credentials\n" f" Email: {member_email}\n" f" Initial password: {initial_password}\n\n" f"{security_note}\n\n" f"{unexpected_contact}\n\n" f"—\n" f"{BRAND_NAME}\n" f"{login_url.rsplit('/login', 1)[0] or login_url}\n" f"This is a one-time account notification from {BRAND_NAME} on behalf of " f"{organization}. You cannot unsubscribe from required account emails." ) preheader = ( f"{manager} invited you to join {organization}. " f"Use the sign-in details below to access your work inbox." ) safe_first = _escape(first_name) safe_manager = _escape(manager) safe_org = _escape(organization) safe_email = _escape(member_email) safe_password = _escape(initial_password) safe_login = _escape(login_url) safe_manager_email = _escape(manager_address) safe_preheader = _escape(preheader) safe_security = _escape(security_note) safe_unexpected = _escape(unexpected_contact) safe_why_received = _escape(why_received) body_html = f""" {_escape(subject)}
{safe_preheader}
gentic.email

Work email invitation

{safe_manager} invited you to join
{safe_org}

Hello {safe_first},

{safe_why_received}

Account details

Organization {safe_org}
Work email {safe_email}
Initial password {safe_password}
Sign in to {BRAND_NAME}

{safe_security}

{safe_unexpected}

{BRAND_NAME} · {BRAND_HANDLE}

One-time account notification from {BRAND_NAME} on behalf of {safe_org}. {" Questions? Reply to " + safe_manager_email + "." if manager_address else ""}

""" return subject, body_text, body_html