Use cases and traces
Each e-mail can say which use case sent it, and what happened to it shows up in that case's trace.
A confirmation, a receipt, «your bread is ready»: every e-mail your app sends exists because of something a person did. Mail records which use case sent it, so «did the confirmation of this order arrive?» is one click from the order.
Saying the case
await mail.send({
from: 'La Espiga <orders@laespiga.co>',
to: 'ana@example.com',
template: 'order-ready',
data: { name: 'Ana', order: '1042' },
case: 'place-order',
});or the header Sypnia-Case: place-order, on the API and on the SMTP relay. The id is the one in your map, from cases/<area>/<id>.case.yaml (Cases).
When your server is traced with Telemetry’s SDK, the case of the current request is already known: @sypnia/mail reads it and sends the trace along, so you can leave case out.
The case is kept with the e-mail and on every one of its events, so you can search by it:
npx @sypnia/mail events --case place-order --type bounced --since 7dThe case says which e-mails it sends
id: place-order
title: Place an order
actor: customer
mail:
sends: [order-ready]The Cases check compares that with what really happens: a case that sends a template it does not list, or lists one it never sends, is reported.
In the trace
The send is a step (a span) inside the trace of its case, next to the database queries and the page that started it. What happens later is added to the same span when Mail learns it, even hours afterwards:
On the span mail.send order-ready | What it says |
|---|---|
| the send | the template and its version, how many recipients, whether it was queued, suppressed or rejected |
delivered, delivery_delayed | when the receiving server accepted it, or why it is still trying |
bounced, complained | the kind of bounce or the complaint; the span is marked as an error |
No span carries the body or the addresses. With Sypnia Telemetry, «Place an order sends the confirmation, and this one bounced» is in the same trace as the order, and in Sypnia Cases each case shows how many of its e-mails were delivered, bounced or marked as spam.