Admin
Email Templates
| Path | /email-templates |
|---|---|
| Status | live |
| Drill-down pages | /email-management |
| Pop-ups | Template editor, Send a test email |
| Tabs | Templates / Sent log; English / Spanish |
| API routes | /api/email-templates/api/email-templates/options/api/email-templates/sends/api/email-templates/:key |
What's on the page
- Templates tab: Audience buttons with counts (All, Patients, Pulse users, Internal alerts), App, Category (with counts) and a search over name, key, category, subject and description. Columns: Template (name and key), Category (and app), Subject, Sent, Problems (failed, not sent, or sent with some addresses skipped), Last sent, Status (Active / Paused, ES when a Spanish message is written), Test and Edit. Patients first, then Pulse users, then internal alerts; every column but Subject sorts.
- Clicking Sent or Not sent opens the Sent log for that template.
- Edit opens one template (its full text is loaded only then): name, active switch, description, From, Reply-to, To (always), BCC (always), English and Spanish subject and HTML message, placeholders to insert, a warning for placeholders the sender doesn't fill, and a live preview with sample values.
- Send a test email: 1โ10 addresses (remembered in the browser, devteam by default), filled with sample values, subject starts with [TEST]; from the editor it sends what is on screen, saved or not. Tests are not written to the send log.
- Sent log tab: Template, Status (Sent, Failed, Not sent, or Sent with some addresses skipped), App (the apps that logged sends) and Date Range filters (default All Time); When, Template (app, ES, ref), To, Subject, Provider, Status (and the error). Paged on the server, newest first.
- Filters, sort, page and tab are kept in the link.
Business rules
Data comes from: email_templates (one row per email the apps send; key is the id the senders use) and email_sends (one row per send attempt). API: GET /api/email-templates (one page of templates), /options (filter choices with counts), /sends (one page of the send log), /:key (one template in full), PUT /:key, POST /:key/test.
How it works:
- Access is checked on the server: the Email Templates key for every template, or Email Templates (CandidPro only) for the CandidPro patient emails only. Admins are not let in by role alone, because a template saved here goes straight to patients and staff. A template outside your scope reads as "No such template".
- Saving checks every field: the English subject and message can't be emptied; From and Reply-to must be one email address; To and BCC must be email addresses (at most 25, stored lower-case, once each); text has length limits. A bad value is refused with a message naming it. Two templates can't have the same name.
- Every save is in the Audit Log: who, and the old and new value of each field saved.
- Sending (all apps): addresses that aren't email addresses (e.g. a phone number in a staff email field) are dropped before sending, so the rest still get the email, and the log row says how many were skipped (counted under Problems); if none is left the send is logged as Not sent, "No valid email address". "Name <a@b.com>" is read as a@b.com. The send log records which provider took the email (SMTP2GO first, Resend as fallback) or each provider's reason when neither did.
- On staging the recipient and subject in the log are read from their encrypted copies; live stores them as plain text until the HIPAA cutover.
Open questions (need your answer)
Known problems:
- 3 staff on live have a phone number in their work email field, so they get no staffing emails (their sends show "Not sent"). Fix the email on the Staff page.
Database tables & columns
| Table | Columns used |
|---|---|
email_sends | app, error, id, lang, provider, recipients, ref, sent_at, sent_by, status, subject, template_key, to_email |
email_templates | active, app, audience, bcc_emails, body_en, body_es, category, description, from_email, key, name, reply_to, subject_en, subject_es, to_emails, trigger_event, updated_at, updated_by, variables |
File structure
Its own files
- apps/
- web/
- src/
- features/
- email-templates/
- components/
- SendLogTab.tsx
- SendTestDialog.tsx
- TemplateEditor.tsx
- TemplatesTab.tsx
- pages/
- EmailTemplatesPage.tsx
- api.ts
- index.ts
- template-text.ts
- components/
- email-templates/
- features/
- src/
- worker/
- src/
- features/
- email-templates/
- __tests__/
- service.test.ts
- index.ts
- queries.ts
- routes.ts
- service.ts
- __tests__/
- email-templates/
- features/
- src/
- web/
Shared code it uses (followed through its imports and the helpers its API calls; sign-in/access plumbing and UI primitives left out)
- apps/
- web/
- src/
- components/
- data/
- DataTable.tsx
- forms/
- DatePicker.tsx
- reports/
- DentrixSourceNote.tsx
- FilterSelect.tsx
- HowItWorksNote.tsx
- ReportDateRange.tsx
- ReportHeader.tsx
- sortable-grid.tsx
- TablePagination.tsx
- data/
- hooks/
- usePagedList.ts
- lib/
- date-presets.ts
- services/
- api.ts
- components/
- src/
- worker/
- src/
- db/
- index.ts
- lib/
- dates.ts
- db-errors.ts
- list-query.ts
- services/
- email-templates.ts
- phi-read.ts
- utils/
- crypto.ts
- email.ts
- phi-access.ts
- phi-crypto.ts
- db/
- src/
- web/