> For the complete documentation index, see [llms.txt](https://sonic-ai-works.gitbook.io/sonic-networks-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sonic-ai-works.gitbook.io/sonic-networks-docs/documentation/developers/architecture-and-runtime/mail-and-notification-architecture.md).

# Mail & Notification Architecture

SONIC v1.0.0 transactional-mail architecture for queue-only application delivery, welcome and security templates, preferences, Resend/Postmark adapters, durable idempotency, retries and delivery truth

Transactional mail is server-side and asynchronous. Application routes enqueue jobs; provider execution is worker-only.

## Canonical structure

```
templates/mail/
├── welcome.ts
├── verify-email.ts
├── workspace-invite.ts
├── role-changed.ts
├── developer-access.ts
├── api-key-created.ts
└── security-alert.ts

lib/mail.ts                 queue-only facade
packages/mail/              provider + rendering + preferences + retry
workers/mail/               provider execution boundary
db/migrations/*mail*        durable jobs and delivery state
```

## Delivery flow

```
domain event
→ durable mail job
→ preference evaluation
→ idempotency claim
→ template render
→ Resend / Postmark
→ provider message ID
→ SENT / DELIVERED / BOUNCED / FAILED
→ bounded retry or terminal handling
```

## Categories

| Category  | Examples                  | Optional? |
| --------- | ------------------------- | --------- |
| SECURITY  | security alerts           | No        |
| ACCOUNT   | welcome, verification     | No        |
| WORKSPACE | invitation, role change   | No        |
| DEVELOPER | optional developer digest | Yes       |
| PRODUCT   | optional product updates  | Yes       |

A marketing preference must never suppress security, account or workspace safety messages.

## Idempotency

Recommended welcome key:

```
welcome:<sonicUserId>:v1
```

The durable delivery store also binds the key to a payload hash. Reusing the same key with different content is a conflict rather than a second send.

## Retry policy

Retry selected transient failures such as rate limits and provider 5xx responses with bounded exponential delay. Permanent validation/provider errors fail terminally instead of retrying forever.

## Role and Developer notifications

Role-change and API-key-created mail may contain the new role, key name or environment, but never API-key secrets. Welcome-mail failure does not roll back a valid account/workspace/chat bootstrap.

## Delivery truth

A provider message ID proves request acceptance, not inbox delivery or reading. Delivery/bounce events, when configured and verified, update durable state independently.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sonic-ai-works.gitbook.io/sonic-networks-docs/documentation/developers/architecture-and-runtime/mail-and-notification-architecture.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
