# Task 013 — Email Template Builder

## Objective

Provide reusable email templates with subject/body editor, merge variable preview, and HTML rendering.

## Scope

- `email_templates` model (if not exists)
- Templates API
- UI at `/campaigns/templates` with list and editor
- Variable insertion helper for documented placeholders
- Preview with sample company/person data

**Out of scope:** Drag-drop visual builder, AMP email.

## Requirements

1. Store `subject`, `htmlBody`, optional `textBody`.
2. Validate unknown merge variables warn in UI.
3. Templates selectable in campaign wizard.

## Files to create or modify

| Path | Action |
|------|--------|
| `src/app/campaigns/templates/**` | Create |
| `src/app/api/templates/**` | Create |
| `src/services/template.service.ts` | Create |
| `docs/06-campaign-system.md` | Variables |
| `docs/05-email-system.md` | Composition |
| `docs/16-changelog.md` | Entry |

## Acceptance criteria

- [ ] Create, edit, delete templates
- [ ] Preview renders HTML safely (sanitized)
- [ ] Campaign wizard lists templates

## Documentation updates required

- `docs/06-campaign-system.md`
- `docs/05-email-system.md`
- `docs/16-changelog.md`
