Emails and messaging
What it is
Every email Payability sends to a supplier passes through the messaging service and is visible here. Emails are not fire-and-forget: many are queued pending approval, can be previewed as rendered HTML, approved or cancelled individually or as a batch, and carry their own event history.
Where it lives
| Concern | Location |
|---|---|
Routes |
|
Components |
|
Service |
|
Model |
|
Settings |
|
Supplier preferences |
|
|
|
Email types
crm-tools/emails/email-types.ts:
| Enum member | Wire value | In filters | Meaning |
|---|---|---|---|
|
|
yes |
Sent manually from a supplier page. |
|
|
yes |
Generated from a CRM note. |
|
|
yes |
A group of batch emails (the container). |
|
|
yes |
Automatic email, typically fired by an event rule. |
|
|
yes |
Task assignment/change notification. |
|
|
no |
An individual email inside a batch group — deliberately excluded from the filter list so that batches appear once, as their group. |
|
The wire values are inconsistent: |
Default filter selection (EmailsStatusService.getDefaultFiltersType) is
AUTO_EMAIL, NOTE_EMAIL, EMAIL_SUPPLIER, BATCH_GROUP — so task notifications are
hidden until explicitly requested.
Statuses
export enum EmailStatuses { SENT = 'sent', PENDING = 'pending', CANCELLED = 'cancelled', SENDING = 'sending' }
PENDING means awaiting operator approval, not "queued for delivery" — that is
SENDING. EmailsStatusService provides the predicates (isPending, isSend,
isBatchGroup) and the type-name lookup; use them rather than comparing strings.
An EmailActions enum in the same file names the operations (approve, …).
Endpoints
All on messagingUrl:
| Endpoint | Purpose |
|---|---|
|
The email log. |
|
Create/queue an email ( |
|
One email. |
|
Update a queued email. |
|
Delete. |
|
Bulk delete. |
|
Delivery/lifecycle events for an email. |
|
Render the email to final HTML. |
|
Render a preview. |
|
Approve one email. |
|
Cancel one email. |
|
Approve a whole batch. |
|
Cancel a whole batch. |
|
Create a batch send. |
|
Approve and cancel are |
emails.service.ts also carries its own headers object (instance id, target UUID)
in the same style as CrmService.
Two render paths
email/rendered/ and email/preview/ both produce HTML from an EmailModel. preview
is the operator-facing "what will this look like" call; rendered produces the final
artefact. Both take the full model, so a preview reflects unsaved edits.
crm-tools/shared/b2b-preview/ and the TinyMCE editor (shared/editor/) are the
composition surface.
Batch email
A batch group is a single logical send to many recipients:
-
POST email/batch/creates it. -
It appears in the timeline as
BATCH_GROUP; the individualBATCH_EMAILitems hang off it. -
email/batch_approve/:batchUuidandemail/batch_cancel/:batchUuidact on the whole group. -
The CRM store keeps a separate
batchEmailsstream, loaded byFETCH_CRM_BATCH_EMAILSand read throughselectCrmBatchEmails.
Bulk email creation from a CSV is a Manage operation — see bulk actions.
Email settings (Manage)
/manage/email-config/list administers templates and configuration.
manage/email-settings/:
| Folder | Purpose |
|---|---|
|
The configuration list. |
|
Add a configuration. |
|
Edit a configuration. |
|
Edit the template variables available to that email. |
|
Delete. |
|
The type badge shown in the list. |
|
The form field definitions. |
Gated by the INT_EMAIL_SETTINGS permission.
Per-supplier email preferences
A supplier can opt out of categories of email.
SupplierEmailPreferencesService on internalApiUrl:
GET suppliers/:supplierKey/email_preference → { emailPreference: EmailPreference[] }
PUT suppliers/:supplierKey/email_preference ← { emailPreferenceCode, isEnabled }
export interface EmailPreference {
code: string; // e.g. "DAILY_EMAILS"
name: string;
description: string;
enabled: boolean;
}
Note the endpoint path is singular email_preference while the response property is
emailPreference wrapping an array, and the update sends one preference at a time
(emailPreferenceCode + isEnabled) rather than the whole set.
The supplier record also carries a coarse sendAutoEmail boolean, independent of these
per-code preferences.
This feature has a spec in .specs/email-preference-management.md — one of the two
reference spec formats. See the spec-driven workflow.
Emails as an event-rule action
send-email is one of the four active event-rule action types
(manage/event-rules/rules-add-edit/action-form/send-email/). A rule matches a domain
event, applies filters, and sends a templated email with context and data mappings.
That is how most AUTO_EMAIL traffic originates. See
events.
SMS
Text messaging shares the messaging backend but not this UI.
suppliers/supplier/supplier-onboarding/smsnumbers/sms-numbers-provider.service.ts
spans authToolsApiUrl (provisioning the number) and messagingUrl (sending). See
onboarding.
Access
/emails denies REST_UW_ACCESS and ADVANCE_AUDITORS, both on the route and in the
sidebar. INT_EMAIL_SETTINGS governs the Manage screens.
Gotchas
| Issue | Detail |
|---|---|
|
Approve and cancel, single and batch. |
Enum values are not derivable |
|
|
|
|
Batches surface as |
The |
It is a routing shim over |
Route name/component mismatch |
|
Two email models share one class |
|