# Bella email — how to build and send

The rules live in **[SPEC.md](SPEC.md)**: anatomy, header, title, customer name,
footer, social links, motion, dark mode and the template inventory. This file is
just the mechanics.

## Build

The fourteen templates are **generated**. Do not edit anything in `templates/` or
`previews/` — the next build overwrites it, and CI fails on a stale or hand-edited file.

```sh
python3 tools/build_emails.py          # rebuild templates/, previews/ and the site manifest
python3 tools/build_emails.py --check  # CI gate: fails if committed output is stale
```

| Edit this | To change |
|---|---|
| `src/content.py` | Copy, subject lines, panels, actions, readiness |
| `tools/build_emails.py` | Layout, styling, the rules the build enforces |
| `tools/generate_tokens.py` | Colour values — then re-run it, then re-run the email build |

The build enforces what reviewers otherwise miss: subject ≤ 45 characters, one
primary action, no unsubscribe on transactional mail, motion on lifecycle mail only,
and no animation start state in an inline style.

## What gets generated

| Path | What it's for |
|---|---|
| `templates/<slug>.html` | **What you send.** Keeps the Liquid tags OneSignal personalises |
| `templates/<slug>.txt` | The plain-text alternative. Paste into OneSignal's text body |
| `previews/<slug>.html` | Liquid resolved to its defaults, for looking at. Never sent |
| `../js/email-manifest.js` | Drives the gallery on the brand site |

## Send

Paste the HTML into OneSignal's **code** editor — not the drag-and-drop editor,
which rewrites the markup — and the `.txt` into the plain-text body. Without a
`text/plain` part, spam filters score the message worse.

Subject and preheader are set on the OneSignal template, not in the HTML. Keep the
hidden preheader `div`: it is what the inbox list shows.

Before sending, replace every image path with a hosted URL and every ALL-CAPS
placeholder. The full list is in [SPEC.md §12](SPEC.md#12-placeholders).

Trigger from the backend, not the app — `POST /notifications` with `template_id` and
`include_aliases: {external_id: [...]}` — so the email still fires if the app is
killed mid-flow.

## Adding a template

1. Add an `Email(...)` to `src/content.py`, including its `Readiness(...)`.
2. Need a new icon? Add one line to `ICONS` in `tools/render_email_icons.py` and
   re-run it. Sources are the app's own SVGs.
3. `python3 tools/build_emails.py && python3 tools/check_links.py`.

## Note

This repo is authoritative for the email system. A stale copy exists at
`bella-mobile-app/design-system/email/` from before this was split into its own
repository — don't edit that one.
