# Reference implementation on AWS

> Every AWS service Mail uses in Sypnia Cloud, and how.

Applies to: Sypnia Cloud (paid service).  
Source: https://mail.docs.sypnia.com/architecture/reference-implementation-aws/

For agents: Mail on AWS: SES (SendRawEmail, Easy DKIM, configuration set per domain, receipt rules, verdicts); SNS → SQS (+ DLQ) for events; Lambda for API, sender, event receiver, webhook dispatcher, inbound parser; ECS Fargate + NLB for SMTP relay 587/465; CloudFront for API and tracking; RDS Postgres; S3 bodies/attachments/raw inbound with lifecycle + KMS; EventBridge Scheduler for scheduled e-mails and warm-up; CloudWatch alarms on bounce/complaint rates; everything in us-east-2, a region reserved for customers' mail (Sypnia's own mail goes from another region); one SES tenant per customer; mailboxes = SES receiving → S3 → mailbox store in Postgres + webmail/JMAP API/MCP, plus IMAP and SMTP submission with Stalwart on ECS.

**Figure**: Sypnia Mail on AWS: the API and the relay, the sender, SES and the event path back.

The API runs on Lambda behind CloudFront; the SMTP relay runs on ECS Fargate behind a Network Load Balancer, because SMTP needs long TCP connections. The sender and the event receiver are Lambda functions. Amazon SES sends and receives; its events go through SNS to SQS. Postgres on RDS holds the state and S3 holds bodies, attachments and raw inbound messages.

| Service                   | Used for                                                                                                                                                                                                                      |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Amazon SES**            | sending (`SendRawEmail`), DKIM signing with Easy DKIM, a configuration set per domain, **one tenant per customer** (its own reputation and automatic pause), receipt rules for inbound and mailboxes, virus and spam verdicts |
| **SNS → SQS**             | SES events (delivery, bounce, complaint, open, click) into a queue the event receiver reads, with a dead-letter queue                                                                                                         |
| **Lambda**                | the API, the sender (triggered every few seconds and by new e-mails), the event receiver, the webhook dispatcher, the inbound parser                                                                                          |
| **ECS Fargate + NLB**     | the SMTP relay on ports 587 and 465                                                                                                                                                                                           |
| **CloudFront**            | `mail.api.sypnia.com` and the tracking links                                                                                                                                                                                  |
| **RDS for PostgreSQL**    | the `sypnia_mail` schema, including the mailbox store: inboxes, conversations, messages, folders, labels and search                                                                                                           |
| **S3**                    | bodies, attachments and raw inbound messages, with lifecycle rules for retention, encrypted with KMS                                                                                                                          |
| **EventBridge Scheduler** | scheduled e-mails and the daily warm-up step                                                                                                                                                                                  |
| **KMS**                   | encryption of storage and of webhook secrets                                                                                                                                                                                  |
| **CloudWatch**            | metrics, alarms on bounce and complaint rates per sending domain                                                                                                                                                              |

## Region

Everything above runs in **`us-east-2` (Ohio)**, a region reserved for customers' mail. Amazon SES counts reputation, reviews and pauses per account **and per region**, so customers' sending can never pause Sypnia's own e-mails, which go out from another region. `us-east-2` was chosen because it offers SES sending, the SMTP interface, email receiving and tenant management, and it sits next to the rest of Sypnia Cloud in `us-east-1`. See [Reputation](https://mail.docs.sypnia.com/deliverability/reputation-and-warm-up) for how each customer is isolated within the region.

## Mailboxes

[Mailboxes](https://mail.docs.sypnia.com/mailboxes) are built on the same pieces: SES receiving writes each message to S3, a Lambda parses it into the mailbox store in Postgres (with full-text search), and the webmail, the API and MCP read from there. Replies go out through the sender like any other e-mail. IMAP and SMTP submission for mail apps run on a mail server (Stalwart) on ECS next to the relay; the [design decisions](https://mail.docs.sypnia.com/reference/decisions) explain the trade-off.
