Skip to content

Email Templates

The email templates module provides a shared foundation for all outbound emails — notifications, invitations, and reports. Every template uses inline style attributes instead of <style> blocks, so emails render correctly in Gmail and other clients that strip embedded CSS.

All templates live at src/bases/email/templates/ and share a common structure:

build_email_html(title, body_html, footer_text)
→ Branded HTML shell (header, accent bar, body card, footer)
→ Template-specific inner HTML
→ styled_markdown_to_html() for rich content

The base shell (build_email_html) wraps any inner HTML in a consistent layout: dark header with “Loquent” branding, an amber accent bar, a white content card, and a grey footer.

Builds the branded HTML shell used by all Loquent emails.

src/bases/email/templates/base_email_template.rs
pub fn build_email_html(
title: &str, // <title> tag and hidden preheader
body_html: &str, // Inner content placed inside the white card
footer_text: &str, // Text shown in the footer area
) -> String
src/bases/email/templates/markdown_utils.rs
/// Escapes HTML special characters to prevent XSS.
pub fn escape_html(s: &str) -> String
/// Converts markdown to an HTML fragment (supports tables).
pub fn markdown_to_html(markdown: &str) -> String
/// Converts markdown to HTML with inline styles on every element.
/// Use this for email content — it ensures compatibility with
/// clients that strip <style> blocks.
pub fn styled_markdown_to_html(markdown: &str) -> String

styled_markdown_to_html applies inline styles to all HTML elements: headings, paragraphs, lists, blockquotes, tables, code spans, links, and horizontal rules. All styles use the Loquent design tokens (dark navy text, amber accents, grey backgrounds).

Renders a category-aware notification card with a colored left border accent.

src/bases/email/templates/notification_email_template.rs
pub fn build_notification_email(
title: &str,
body: Option<&str>,
category: &str, // "call", "todo", "todo_completed", or fallback
) -> (String, String) // (text_body, html_body)

Category determines the badge color and label:

CategoryColorLabel
callBlue (#3b82f6)CALL
todoAmber (#f59e0b)TODO
todo_completedGreen (#22c55e)COMPLETED
OtherRed (#ef4444)SYSTEM

Renders a rich call email with contact info, transcription, and AI analysis.

src/bases/email/templates/call_notification_email_template.rs
pub struct CallEmailData {
pub date: String,
pub receiving_phone_label: Option<String>,
pub receiving_phone_number: String,
pub caller_number: String,
pub contact_name: Option<String>,
pub contact_company: Option<String>,
pub transcription: Option<String>,
pub analysis_items: Vec<String>,
}
pub fn build_call_notification_email(
title: &str,
call: &CallEmailData,
) -> (String, String, String) // (subject, text_body, html_body)

The call template displays:

  • A “NEW CALL” label with the call date
  • Receiving phone line (label + number)
  • Caller info (contact name, company, phone number)
  • Transcription in a blockquote
  • Analysis rendered as styled markdown

Renders a centered invitation card with a CTA button.

src/bases/email/templates/invitation_email_template.rs
pub fn build_invitation_email(
org_name: &str,
accept_url: &str,
) -> (String, String) // (text_body, html_body)

The notify_service dispatches to the correct template based on the notification entity:

// In send_notification_email()
match entity {
Some(NotificationEntity::Call(call_id)) => {
// Fetches call + contact data from DB
// Uses build_call_notification_email()
fetch_and_build_call_email(call_id, org_id, title, db).await?
}
_ => {
// Falls back to the base notification template
build_notification_email(title, body, category)
}
}

The report module also uses styled_markdown_to_html and build_email_html to render daily report emails with consistent branding.

FilePurpose
src/bases/email/templates/mod.rsPublic re-exports
src/bases/email/templates/base_email_template.rsBranded HTML shell
src/bases/email/templates/markdown_utils.rsMarkdown → inline-styled HTML
src/bases/email/templates/notification_email_template.rsGeneric notification card
src/bases/email/templates/call_notification_email_template.rsRich call email with contact + analysis
src/bases/email/templates/invitation_email_template.rsOrg invitation with CTA button
src/mods/notification/services/notify_service.rsTemplate dispatch logic
src/mods/report/services/report_markdown_to_html_email_service.rsReport email (uses shared utils)