---
id: w3/m9/t003
title: Email delivery via the existing `mailer.SMTP` (reuse the `w4/m12` invite-email pattern)
worker: worker3
status: todo
estimate: 30m
depends_on: [w3/m9/t002]
---

## Objective

Deliver deploy notification emails to workspace members using the existing SMTP mailer.

## Context

- `lego/backend/internal/mailer/mailer.go` — `mailer.New(addr, from, username, password)`, already used for workspace invites (`w4/m12`).
- `BEX_SMTP_ADDR`/`BEX_SMTP_FROM`/`BEX_SMTP_USERNAME`/`BEX_SMTP_PASSWORD` env vars (unset ⇒ no email, per existing convention for invites).

## Steps

1. Add an email template for deploy success/failure (service name, deploy id, status, link to the dashboard).
2. Wire the notification hook from t002 to call `mailer.SMTP` for each subscribed member's email (resolve via Kratos admin, same pattern as `w4/m12`).
3. Follow the existing convention: unset SMTP config ⇒ notification recorded but not emailed (mirrors invite-email behavior), not a hard error.

## Files

- `lego/backend/internal/notifications/`
- `lego/backend/internal/mailer/`

## Acceptance criteria

- [ ] A deploy failure/success with SMTP configured sends a real email via Mailpit (local) verified in a test or manual run.
- [ ] With SMTP unset, the notification path degrades the same way invites do (recorded, not emailed, no error).

## Out of scope

- Non-email delivery channels (Slack, webhook) — email only for this milestone.
