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.
Architecture
Section titled “Architecture”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 contentThe 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.
Public API
Section titled “Public API”build_email_html
Section titled “build_email_html”Builds the branded HTML shell used by all Loquent emails.
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) -> StringMarkdown Utilities
Section titled “Markdown Utilities”/// 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) -> Stringstyled_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).
Notification Email
Section titled “Notification Email”Renders a category-aware notification card with a colored left border accent.
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:
| Category | Color | Label |
|---|---|---|
call | Blue (#3b82f6) | CALL |
todo | Amber (#f59e0b) | TODO |
todo_completed | Green (#22c55e) | COMPLETED |
| Other | Red (#ef4444) | SYSTEM |
Call Notification Email
Section titled “Call Notification Email”Renders a rich call email with contact info, transcription, and AI analysis.
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
Invitation Email
Section titled “Invitation Email”Renders a centered invitation card with a CTA button.
pub fn build_invitation_email( org_name: &str, accept_url: &str,) -> (String, String) // (text_body, html_body)Template Dispatch
Section titled “Template Dispatch”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.
Key Files
Section titled “Key Files”| File | Purpose |
|---|---|
src/bases/email/templates/mod.rs | Public re-exports |
src/bases/email/templates/base_email_template.rs | Branded HTML shell |
src/bases/email/templates/markdown_utils.rs | Markdown → inline-styled HTML |
src/bases/email/templates/notification_email_template.rs | Generic notification card |
src/bases/email/templates/call_notification_email_template.rs | Rich call email with contact + analysis |
src/bases/email/templates/invitation_email_template.rs | Org invitation with CTA button |
src/mods/notification/services/notify_service.rs | Template dispatch logic |
src/mods/report/services/report_markdown_to_html_email_service.rs | Report email (uses shared utils) |