@somewhere-cloud/cli 0.38.154 → 0.38.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/docs/adopt.md +39 -0
- package/dist/docs/analytics.md +161 -0
- package/dist/docs/api-reference.md +339 -0
- package/dist/docs/api-surface.md +2067 -0
- package/dist/docs/app-mcp.md +162 -0
- package/dist/docs/architecture-patterns.md +334 -0
- package/dist/docs/auth-client.md +531 -0
- package/dist/docs/billing.md +76 -0
- package/dist/docs/browser.md +639 -0
- package/dist/docs/calendar.md +298 -0
- package/dist/docs/changes.md +323 -0
- package/dist/docs/cli.md +407 -0
- package/dist/docs/common-mistakes.md +199 -0
- package/dist/docs/connect-agent.md +72 -0
- package/dist/docs/cors.md +114 -0
- package/dist/docs/cron.md +167 -0
- package/dist/docs/database-engine.md +167 -0
- package/dist/docs/declared-data.md +1656 -0
- package/dist/docs/declared-files.md +475 -0
- package/dist/docs/deploy-intelligence.md +188 -0
- package/dist/docs/deploy.md +733 -0
- package/dist/docs/design-system.md +273 -0
- package/dist/docs/dev-environments.md +496 -0
- package/dist/docs/domain-ownership.md +31 -0
- package/dist/docs/domains.md +370 -0
- package/dist/docs/feedback.md +88 -0
- package/dist/docs/file-tools.md +116 -0
- package/dist/docs/functions.md +489 -0
- package/dist/docs/getting-started.md +238 -0
- package/dist/docs/github.md +95 -0
- package/dist/docs/google-calendar.md +212 -0
- package/dist/docs/groups.md +836 -0
- package/dist/docs/guarantees.md +58 -0
- package/dist/docs/handled-for-you.md +224 -0
- package/dist/docs/inspect.md +171 -0
- package/dist/docs/limits.md +68 -0
- package/dist/docs/live-data.md +197 -0
- package/dist/docs/live.md +92 -0
- package/dist/docs/local-dev.md +30 -0
- package/dist/docs/migration-supabase.md +58 -0
- package/dist/docs/payments.md +1102 -0
- package/dist/docs/portability.md +194 -0
- package/dist/docs/postgres.md +301 -0
- package/dist/docs/pricing-comparison.md +42 -0
- package/dist/docs/pricing.md +39 -0
- package/dist/docs/project-groups.md +107 -0
- package/dist/docs/projects.md +380 -0
- package/dist/docs/recipe-ai-agent.md +112 -0
- package/dist/docs/recipe-ai-features.md +227 -0
- package/dist/docs/recipe-ai-receipts.md +783 -0
- package/dist/docs/recipe-background-jobs.md +369 -0
- package/dist/docs/recipe-booking.md +348 -0
- package/dist/docs/recipe-csv-import.md +390 -0
- package/dist/docs/recipe-ecommerce.md +127 -0
- package/dist/docs/recipe-email.md +282 -0
- package/dist/docs/recipe-escalation.md +133 -0
- package/dist/docs/recipe-file-uploads.md +159 -0
- package/dist/docs/recipe-import-app.md +110 -0
- package/dist/docs/recipe-login.md +457 -0
- package/dist/docs/recipe-multi-chat.md +198 -0
- package/dist/docs/recipe-paid-api.md +161 -0
- package/dist/docs/recipe-pdfs.md +205 -0
- package/dist/docs/recipe-push-notifications.md +107 -0
- package/dist/docs/recipe-seo.md +200 -0
- package/dist/docs/recipe-signed-in-app.md +330 -0
- package/dist/docs/render.md +99 -0
- package/dist/docs/rooms.md +554 -0
- package/dist/docs/sdk.md +287 -0
- package/dist/docs/sdks.md +24 -0
- package/dist/docs/search.md +199 -0
- package/dist/docs/security-model.md +168 -0
- package/dist/docs/setup.md +212 -0
- package/dist/docs/smoke.md +102 -0
- package/dist/docs/speed.md +298 -0
- package/dist/docs/sql-compatibility.md +96 -0
- package/dist/docs/sw.agent.md +248 -0
- package/dist/docs/sw.ai.md +1291 -0
- package/dist/docs/sw.auth.md +1811 -0
- package/dist/docs/sw.billing.md +171 -0
- package/dist/docs/sw.db.md +2128 -0
- package/dist/docs/sw.email.md +661 -0
- package/dist/docs/sw.endpoint.md +187 -0
- package/dist/docs/sw.env.md +303 -0
- package/dist/docs/sw.fetch.md +115 -0
- package/dist/docs/sw.fs.md +424 -0
- package/dist/docs/sw.groups.md +836 -0
- package/dist/docs/sw.image.md +69 -0
- package/dist/docs/sw.jobs.md +520 -0
- package/dist/docs/sw.logs.md +61 -0
- package/dist/docs/sw.mail.md +106 -0
- package/dist/docs/sw.notifications.md +78 -0
- package/dist/docs/sw.push.md +161 -0
- package/dist/docs/sw.rateLimit.md +67 -0
- package/dist/docs/sw.web.md +128 -0
- package/dist/docs/tasks.md +269 -0
- package/dist/docs/test.md +220 -0
- package/dist/docs/tool-reference-account.md +7 -0
- package/dist/docs/tool-reference-ai.md +121 -0
- package/dist/docs/tool-reference-analytics.md +37 -0
- package/dist/docs/tool-reference-api.md +19 -0
- package/dist/docs/tool-reference-artifacts.md +35 -0
- package/dist/docs/tool-reference-auth.md +163 -0
- package/dist/docs/tool-reference-browser.md +114 -0
- package/dist/docs/tool-reference-code.md +26 -0
- package/dist/docs/tool-reference-connect.md +21 -0
- package/dist/docs/tool-reference-cron.md +48 -0
- package/dist/docs/tool-reference-db.md +282 -0
- package/dist/docs/tool-reference-domains.md +107 -0
- package/dist/docs/tool-reference-email.md +55 -0
- package/dist/docs/tool-reference-env.md +19 -0
- package/dist/docs/tool-reference-feedback.md +56 -0
- package/dist/docs/tool-reference-fs.md +265 -0
- package/dist/docs/tool-reference-github.md +57 -0
- package/dist/docs/tool-reference-groups.md +85 -0
- package/dist/docs/tool-reference-help.md +29 -0
- package/dist/docs/tool-reference-jobs.md +39 -0
- package/dist/docs/tool-reference-live.md +48 -0
- package/dist/docs/tool-reference-logs.md +16 -0
- package/dist/docs/tool-reference-payments.md +44 -0
- package/dist/docs/tool-reference-project.md +706 -0
- package/dist/docs/tool-reference-push.md +78 -0
- package/dist/docs/tool-reference-rate-limit.md +18 -0
- package/dist/docs/tool-reference-search.md +68 -0
- package/dist/docs/tool-reference-security.md +42 -0
- package/dist/docs/tool-reference-smoke.md +17 -0
- package/dist/docs/tool-reference-stock-photos.md +20 -0
- package/dist/docs/tool-reference-tasks.md +73 -0
- package/dist/docs/tool-reference-telegram.md +32 -0
- package/dist/docs/tool-reference-usage.md +9 -0
- package/dist/docs/tool-reference-web.md +71 -0
- package/dist/docs/tool-reference-webhooks.md +9 -0
- package/dist/docs/troubleshooting.md +411 -0
- package/dist/docs/typed-functions.md +94 -0
- package/dist/docs/verify-before-deploy.md +67 -0
- package/dist/docs/vs-supabase.md +75 -0
- package/dist/docs/vs-vercel.md +103 -0
- package/dist/lib/bundle.js +303 -221
- package/dist/lib/bundle.js.map +3 -3
- package/dist/types/lib/test-session.d.ts +8 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +3 -2
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
# Email
|
|
2
|
+
|
|
3
|
+
Send transactional email from a function with `sw.email.send`. There's no
|
|
4
|
+
sender account or domain to set up first. Without a `from`, mail goes out
|
|
5
|
+
from your app's own address, `<your-app-subdomain>@somewhere.site`, labeled
|
|
6
|
+
with your project's name. Replies to that address land in your project
|
|
7
|
+
mailbox (`sw.mail.project.list()`). Sign-in emails
|
|
8
|
+
(verification, magic links, password reset) are sent for you. Every project
|
|
9
|
+
also gets a test inbox, so an agent can sign up, send and read the actual
|
|
10
|
+
message without a real mailbox.
|
|
11
|
+
|
|
12
|
+
The app's own address reaches your project's owner and the app users who
|
|
13
|
+
have verified their email address and signed in at least once. The platform
|
|
14
|
+
adds an unsubscribe line and one-click unsubscribe headers to every such
|
|
15
|
+
email; a user who unsubscribes is refused afterwards
|
|
16
|
+
(`RECIPIENT_UNSUBSCRIBED`). To email anyone else, verify your own sender
|
|
17
|
+
domain and pass `from`.
|
|
18
|
+
|
|
19
|
+
A guest account (connected without signing up) cannot send email, and neither
|
|
20
|
+
can the apps it deploys: `sw.email.send` and notification email answer `CLAIM_ACCOUNT_REQUIRED` (403) until the owner claims the
|
|
21
|
+
account by verifying their email.
|
|
22
|
+
|
|
23
|
+
Save first, await durable job admission, then respond. Queued is not sent; the signed handler records the email outcome. `sw.waitUntil` is not a runtime API.
|
|
24
|
+
|
|
25
|
+
If sending email is the action itself, await `sw.email.send` and show its
|
|
26
|
+
confirmed result. This is different from a notification after a saved change.
|
|
27
|
+
|
|
28
|
+
## Send from an authorized action
|
|
29
|
+
|
|
30
|
+
This function emails the signed-in user a copy of something they wrote. The
|
|
31
|
+
recipient is the user's own address, used only once they have verified it,
|
|
32
|
+
never one from the request body. A signed-in session shows who is asking; a
|
|
33
|
+
password sign-up can name any address, so the function checks
|
|
34
|
+
`user.email_verified` first (`sw.auth` → `email-verification`).
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
// api/email-me.ts
|
|
38
|
+
export default async function emailMe(
|
|
39
|
+
request: Request,
|
|
40
|
+
sw: SomewhereRuntimeContext,
|
|
41
|
+
): Promise<Response> {
|
|
42
|
+
if (request.method !== 'POST') {
|
|
43
|
+
return new Response('Use POST.', { status: 405, headers: { Allow: 'POST' } });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const user = await sw.auth.fromRequest(request);
|
|
47
|
+
if (!user) {
|
|
48
|
+
return Response.json({ error: 'Sign in to email yourself.' }, { status: 401 });
|
|
49
|
+
}
|
|
50
|
+
if (user.email_verified !== true) {
|
|
51
|
+
return Response.json({ error: 'Verify your email address first.' }, { status: 403 });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const input: unknown = await request.json().catch(() => null);
|
|
55
|
+
const fields = typeof input === 'object' && input !== null ? input : {};
|
|
56
|
+
const title = 'title' in fields ? fields.title : undefined;
|
|
57
|
+
const body = 'body' in fields ? fields.body : undefined;
|
|
58
|
+
const requestId = 'request_id' in fields ? fields.request_id : undefined;
|
|
59
|
+
if (typeof title !== 'string' || !title.trim() || title.length > 120
|
|
60
|
+
|| typeof body !== 'string' || body.length > 10000
|
|
61
|
+
|| typeof requestId !== 'string' || !/^[\w-]{8,64}$/.test(requestId)) {
|
|
62
|
+
return Response.json({ error: 'Send a title, a body and a request_id.' }, { status: 400 });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const allowance = await sw.rateLimit.check(`email-me:${user.id}`, 10, 3600);
|
|
66
|
+
if (!allowance.allowed) {
|
|
67
|
+
return Response.json({ error: 'You have sent a lot of email. Try again later.' }, { status: 429 });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const sent = await sw.email.send({
|
|
72
|
+
to: user.email,
|
|
73
|
+
subject: `Your note: ${title.trim()}`,
|
|
74
|
+
text: body,
|
|
75
|
+
// A retried request reuses request_id, so it gets the stored message instead of a second send.
|
|
76
|
+
idempotency_key: `email-me:${user.id}:${requestId}`,
|
|
77
|
+
});
|
|
78
|
+
return Response.json({ id: sent.id, status: sent.status });
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const code = error instanceof Error && 'code' in error ? String(error.code) : 'EMAIL_FAILED';
|
|
81
|
+
const status = error instanceof Error && 'status' in error ? Number(error.status) : 0;
|
|
82
|
+
// 422 and 429 mean the platform refused this request. Anything else may have reached the provider.
|
|
83
|
+
if (status === 422 || status === 429) {
|
|
84
|
+
return Response.json({ error: 'The email request was refused.', code }, { status });
|
|
85
|
+
}
|
|
86
|
+
return Response.json(
|
|
87
|
+
{ error: 'Could not confirm the email. Check its status before trying again.', code },
|
|
88
|
+
{ status: 502 },
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The page sends a fresh `request_id` for each click, for example
|
|
95
|
+
`crypto.randomUUID()`, and reuses it when it retries that same click.
|
|
96
|
+
|
|
97
|
+
## Test it with the test inbox
|
|
98
|
+
|
|
99
|
+
Deploy, then sign in to your app with a sign-in link sent to an address at
|
|
100
|
+
your project's test domain: `ana@<your-subdomain>.test.somewhere.site`
|
|
101
|
+
(`sw.auth` → `magic-links`). Run the command below and open the link it
|
|
102
|
+
prints; that verifies the address. A password sign-up alone does not, and the
|
|
103
|
+
function above answers it with 403. Send yourself a note, then read what
|
|
104
|
+
arrived:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Replace my-app with your app's subdomain.
|
|
108
|
+
somewhere email test-inbox ana@my-app.test.somewhere.site
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The command prints each captured message, including its subject, text and any
|
|
112
|
+
sign-in link. Sending to a test address returns `status: 'captured'`. The
|
|
113
|
+
message is stored in the test inbox, never delivered, and doesn't count
|
|
114
|
+
toward your email allowance. Sign-up verification and magic-link emails to a
|
|
115
|
+
test address land in the same inbox, so a whole sign-in journey can be
|
|
116
|
+
checked this way.
|
|
117
|
+
|
|
118
|
+
## Read the result
|
|
119
|
+
|
|
120
|
+
`sw.email.send` waits for the email provider's answer. On a real address,
|
|
121
|
+
`status: 'sent'` means the provider accepted the message. Delivery is a later
|
|
122
|
+
event. `sw.email.status(id)` returns the message and its events (`delivered`,
|
|
123
|
+
`bounced`, `opened` and so on). A refused request throws a 422 or 429 error with a
|
|
124
|
+
`code`, such as `MANAGED_SENDER_RECIPIENT_NOT_A_USER` (the built-in sender only
|
|
125
|
+
reaches your verified users and owner) or `EMAIL_SUPPRESSED` (the address bounced or
|
|
126
|
+
complained earlier).
|
|
127
|
+
|
|
128
|
+
**When the outcome is unknown.** A throw of `EMAIL_DELIVERY_UNKNOWN`, or a
|
|
129
|
+
result with `status: 'pending'`, means the platform couldn't confirm the
|
|
130
|
+
provider accepted the message. Look it up first, with `sw.email.status(id)`
|
|
131
|
+
when you have its id, or in `sw.email.history()`. Sending again with the same `idempotency_key` and the same
|
|
132
|
+
message never creates a second send. It returns the stored message with
|
|
133
|
+
`duplicate: true`. For a send whose acceptance was never confirmed, it reports
|
|
134
|
+
`delivery_unknown` instead of sending again. Reusing a key for a different
|
|
135
|
+
message is refused with `IDEMPOTENCY_KEY_CONFLICT`. When the email follows
|
|
136
|
+
work that already succeeded, such as a saved order, record the email's outcome
|
|
137
|
+
on that record instead of failing the whole request.
|
|
138
|
+
|
|
139
|
+
## More on email
|
|
140
|
+
|
|
141
|
+
| Need | Where |
|
|
142
|
+
|---|---|
|
|
143
|
+
| Send from your own domain to anyone: setup and DNS records | `sw.email` → `your-own-sender-domain` |
|
|
144
|
+
| Marketing email: postal address, footer, topics | `sw.email` → `marketing-email` |
|
|
145
|
+
| Every send option and `from` | `sw.email` → `swemailsendmessage` |
|
|
146
|
+
| Result states and every error code | `sw.email` → `result-and-errors` |
|
|
147
|
+
| Sending to many recipients, rate and allowance | `sw.email` → `sending-to-many-recipients`; `pricing` |
|
|
148
|
+
| Test inbox retention and limits | `sw.email` → `test-inbox` |
|
|
149
|
+
| Bounces, complaints, project sending pauses | `sw.email` → `sending-reputation`, `delivery-health-scrub-bounces-before-sending` |
|
|
150
|
+
| Delivery and engagement events | `sw.email` → `delivery-and-engagement-events` |
|
|
151
|
+
| Receiving email | `recipe-email` → `receive-email` |
|
|
152
|
+
| Long or scheduled sends | `sw.jobs`, `cron` |
|
|
153
|
+
|
|
154
|
+
## Your own sender domain
|
|
155
|
+
|
|
156
|
+
The built-in sender needs no setup on any plan, and reaches your project's
|
|
157
|
+
verified users and owner. To email anyone else, such as guest customers or
|
|
158
|
+
newsletter readers, to take replies at your own address, or to send more than
|
|
159
|
+
the built-in sender's daily limit, verify a domain you own once and send from it.
|
|
160
|
+
|
|
161
|
+
Add and verify the domain from a terminal or with the MCP `api` tool.
|
|
162
|
+
Set all four records returned by the first call at your DNS host. The three
|
|
163
|
+
CNAME records enable signing, and the TXT record at `_somewhere.<your domain>`
|
|
164
|
+
proves the project added the domain. Run the verification call until it
|
|
165
|
+
reports the domain as verified.
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
somewhere api POST /v1/email/sender-domains -d '{"project_id":"my-app","domain":"yourapp.com"}'
|
|
169
|
+
# add every entry of dns_records ({ type, name, value }) at your DNS host, then:
|
|
170
|
+
somewhere api POST "/v1/email/sender-domains/yourapp.com/verify?project_id=my-app"
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Both calls return the domain with `verified` and its `dns_records`. Repeat
|
|
174
|
+
the verify call until `verified` is `true`; while a record is missing, the
|
|
175
|
+
verify response's `action_required` says which. A domain is verified only while
|
|
176
|
+
all four records are found, so each check needs the TXT record in place.
|
|
177
|
+
Adding the same domain again returns the existing entry. Removing a domain and
|
|
178
|
+
adding it again gives it a new TXT value; replace the old TXT record. A domain
|
|
179
|
+
bought through the platform, or one using its nameservers, is added and
|
|
180
|
+
verified automatically, TXT record included.
|
|
181
|
+
|
|
182
|
+
Verified domains are also re-checked about once a day. A domain verified
|
|
183
|
+
before the TXT record existed gets its record in `dns_records` on its next
|
|
184
|
+
check, or within a day; add it within 7 days to keep sending verified. Once a
|
|
185
|
+
domain's record is 7 days old, a daily check that can't find it pauses sending
|
|
186
|
+
from the domain (`verified` becomes `false`) until the record is back and the
|
|
187
|
+
verify call finds it. If the domain's three signing (CNAME) records are
|
|
188
|
+
removed, the daily check pauses sending the same way until they are added
|
|
189
|
+
again and the verify call finds them. A domain bought through the platform, or
|
|
190
|
+
one using its nameservers, needs nothing: its records are added for it. If the DNS check itself
|
|
191
|
+
can't complete, nothing changes; the verify call returns 503
|
|
192
|
+
`SENDER_DOMAIN_DNS_CHECK_UNAVAILABLE`.
|
|
193
|
+
|
|
194
|
+
A sending domain belongs to one project. Adding a domain that another project
|
|
195
|
+
has set up for sending returns 409 `SENDER_DOMAIN_IN_USE`; it can be added
|
|
196
|
+
after it is removed there.
|
|
197
|
+
|
|
198
|
+
Adding, checking and removing a sender domain need editor access. Adding one
|
|
199
|
+
needs a paid plan on the project owner's account; on Free the call returns 402
|
|
200
|
+
`UPGRADE_REQUIRED`.
|
|
201
|
+
|
|
202
|
+
Once verified:
|
|
203
|
+
|
|
204
|
+
- **Send with `from`** on that domain, such as
|
|
205
|
+
`from: 'Acme <hello@yourapp.com>'`, to any recipient (example under
|
|
206
|
+
`sw.email.send(message)` below). Suppression, allowance and rate rules
|
|
207
|
+
still apply.
|
|
208
|
+
- **Leaving out `from` still uses the built-in sender**, with its
|
|
209
|
+
recipient limit.
|
|
210
|
+
- **Sign-in emails switch on their own** to `noreply@` your
|
|
211
|
+
earliest-added verified domain.
|
|
212
|
+
- **Marketing sends need your domain.** `category: 'marketing'` without
|
|
213
|
+
`from` returns `CUSTOM_SENDER_REQUIRED`. See "Marketing email" below
|
|
214
|
+
for what else it needs.
|
|
215
|
+
- **A `from` that isn't ready is refused.** A domain not added returns
|
|
216
|
+
`SENDER_DOMAIN_NOT_FOUND`, and one still pending returns
|
|
217
|
+
`SENDER_DOMAIN_NOT_VERIFIED` (400).
|
|
218
|
+
- **To list or remove domains,** use
|
|
219
|
+
`GET /v1/email/sender-domains?project_id=…` or
|
|
220
|
+
`DELETE /v1/email/sender-domains/<domain>?project_id=…`. Removing
|
|
221
|
+
changes nothing at your DNS host.
|
|
222
|
+
|
|
223
|
+
To bring in someone who isn't a user yet, use `sw.auth.invite`
|
|
224
|
+
(`sw.auth` → `invitations`).
|
|
225
|
+
|
|
226
|
+
## Marketing email
|
|
227
|
+
|
|
228
|
+
Newsletters, announcements and offers go with `category: 'marketing'`.
|
|
229
|
+
Each marketing send needs four things:
|
|
230
|
+
|
|
231
|
+
- **`from` on your verified sender domain** (otherwise
|
|
232
|
+
`CUSTOM_SENDER_REQUIRED`).
|
|
233
|
+
- **A `topic`**, one of the ids below (otherwise `EMAIL_TOPIC_REQUIRED`).
|
|
234
|
+
- **An `idempotency_key`** (otherwise `IDEMPOTENCY_KEY_REQUIRED`).
|
|
235
|
+
- **Your postal address on the project**, set once as
|
|
236
|
+
`marketing_postal_address`. Without it the send returns
|
|
237
|
+
`MARKETING_POSTAL_ADDRESS_REQUIRED` and nothing is sent.
|
|
238
|
+
|
|
239
|
+
Set the address with `project_update`, or the API:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
curl -X PATCH https://api.somewhere.cloud/v1/projects/<project_id> \
|
|
243
|
+
-H "Authorization: Bearer $SOMEWHERE_API_KEY" \
|
|
244
|
+
-H 'Content-Type: application/json' \
|
|
245
|
+
-d '{"marketing_postal_address": "1 Main St, Springfield, IL 62701, USA"}'
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
It is read back on the project. `null` clears it. Up to 300 characters;
|
|
249
|
+
line breaks become commas.
|
|
250
|
+
|
|
251
|
+
**The footer.** The platform adds a footer to every marketing email. App
|
|
252
|
+
code cannot remove or change it. It shows:
|
|
253
|
+
|
|
254
|
+
- your `marketing_postal_address`;
|
|
255
|
+
- an "Email preferences or unsubscribe" link to a page where the
|
|
256
|
+
recipient picks topics or unsubscribes from all.
|
|
257
|
+
|
|
258
|
+
The message also gets one-click unsubscribe headers. After a recipient
|
|
259
|
+
turns a topic off, sends on that topic return `RECIPIENT_UNSUBSCRIBED`.
|
|
260
|
+
|
|
261
|
+
**Topics.** The recipient sees these labels on the preferences page:
|
|
262
|
+
|
|
263
|
+
| `topic` | Label |
|
|
264
|
+
|---|---|
|
|
265
|
+
| `project-updates` | Product updates |
|
|
266
|
+
| `milestones` | News |
|
|
267
|
+
| `announcements` | Announcements |
|
|
268
|
+
| `founder-notes` | Notes from the team |
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
// api/_lib/newsletter.ts — the address comes from your own subscriber records.
|
|
272
|
+
export function sendNewsletter(
|
|
273
|
+
sw: SomewhereRuntimeContext,
|
|
274
|
+
issue: { id: string; subject: string; html: string },
|
|
275
|
+
subscriber: { id: string; email: string },
|
|
276
|
+
): Promise<SomewhereEmailSendResult> {
|
|
277
|
+
return sw.email.send({
|
|
278
|
+
to: subscriber.email,
|
|
279
|
+
from: 'News <news@yourapp.com>', // a verified sender domain on this project
|
|
280
|
+
subject: issue.subject,
|
|
281
|
+
html: issue.html,
|
|
282
|
+
category: 'marketing',
|
|
283
|
+
topic: 'announcements',
|
|
284
|
+
idempotency_key: `newsletter:${issue.id}:${subscriber.id}`,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Transactional email (the default category) needs no postal address.
|
|
290
|
+
|
|
291
|
+
## sw.email.send(message)
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
// api/_lib/order-email.ts — call it from a handler that already checked who
|
|
295
|
+
// receives this; the address comes from your saved order, never the request.
|
|
296
|
+
export function sendOrderShipped(
|
|
297
|
+
sw: SomewhereRuntimeContext,
|
|
298
|
+
order: { id: string; email: string; trackingNumber: string },
|
|
299
|
+
): Promise<SomewhereEmailSendResult> {
|
|
300
|
+
return sw.email.send({
|
|
301
|
+
to: order.email,
|
|
302
|
+
subject: 'Your order shipped',
|
|
303
|
+
text: `Tracking: ${order.trackingNumber}`, // or html, or both
|
|
304
|
+
idempotency_key: `order-shipped:${order.id}`,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
The send result's `message_id` is Somewhere's own identifier for the send.
|
|
310
|
+
To thread a reply, read the `Message-ID` header of the message your app
|
|
311
|
+
received and pass it as `in_reply_to`. Pass the earlier `Message-ID` values
|
|
312
|
+
in the thread as a `references` array, in order, ending with the parent.
|
|
313
|
+
Preserve the angle brackets in each value.
|
|
314
|
+
|
|
315
|
+
Test-inbox captures show their own `Message-ID` and any `In-Reply-To` and
|
|
316
|
+
`References` values in `headers`. To see them in the CLI, run
|
|
317
|
+
`somewhere email test-inbox <address> --json`.
|
|
318
|
+
|
|
319
|
+
With no `from`, the message goes from your app's own address,
|
|
320
|
+
`<your-app-subdomain>@somewhere.site`, with the project name as its sender
|
|
321
|
+
label. The response names the sender mode and address. It can only email the
|
|
322
|
+
project's owner and app users who have verified their email address with
|
|
323
|
+
this project and signed in at least once; a pending sign-in or an unverified
|
|
324
|
+
sign-up does not count. Other recipients return
|
|
325
|
+
`MANAGED_SENDER_RECIPIENT_NOT_A_USER`; verify your own sender domain for
|
|
326
|
+
outreach. The platform adds a one-line unsubscribe footer and one-click
|
|
327
|
+
unsubscribe headers; after a user unsubscribes, sends to them return
|
|
328
|
+
`RECIPIENT_UNSUBSCRIBED`. Sign-in emails are not affected. Replies to the
|
|
329
|
+
app's address are recorded in your project mailbox; read them with
|
|
330
|
+
`sw.mail.project.list()`. If the app draws many complaints or bounces, its
|
|
331
|
+
sending pauses (`EMAIL_PROJECT_PAUSED`) without affecting other apps.
|
|
332
|
+
Temporary (unclaimed) apps cannot send. Its `reply_to` must be the project's
|
|
333
|
+
owner or a verified user of the app, the people it may already email (for
|
|
334
|
+
example, a booking confirmation to a visitor that replies to the host); any
|
|
335
|
+
other address returns `REPLY_TO_NEEDS_OWN_DOMAIN`. Each
|
|
336
|
+
project can send at most 500 such emails per UTC day on every plan
|
|
337
|
+
(`EMAIL_SHARED_SENDER_DAILY_LIMIT`). Pass `from` to use your own verified
|
|
338
|
+
sender domain, where `reply_to` takes any address and this daily limit does not apply:
|
|
339
|
+
|
|
340
|
+
```ts
|
|
341
|
+
// api/_lib/order-email-own-domain.ts
|
|
342
|
+
export function sendOrderShippedFromYourDomain(
|
|
343
|
+
sw: SomewhereRuntimeContext,
|
|
344
|
+
order: { id: string; email: string; trackingNumber: string },
|
|
345
|
+
): Promise<SomewhereEmailSendResult> {
|
|
346
|
+
return sw.email.send({
|
|
347
|
+
to: order.email,
|
|
348
|
+
from: 'notifications@yourapp.com', // a verified sender domain on this project
|
|
349
|
+
reply_to: 'support@yourapp.com', // optional
|
|
350
|
+
subject: 'Your order shipped',
|
|
351
|
+
text: `Tracking: ${order.trackingNumber}`,
|
|
352
|
+
idempotency_key: `order-shipped:${order.id}`,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
An explicit `from` must match a verified sender domain on this project.
|
|
358
|
+
Callers cannot explicitly name a platform domain. The managed default is for
|
|
359
|
+
transactional email; add a verified sender domain for your own branding and
|
|
360
|
+
marketing email. The plan's email allowance and send rate limit apply to both.
|
|
361
|
+
Limit: the Free tier has a daily + monthly send cap; paid tiers are metered
|
|
362
|
+
monthly. Read the current per-tier caps from /v1/pricing instead of copying
|
|
363
|
+
them into project policy or application code.
|
|
364
|
+
|
|
365
|
+
The platform sends your app's password reset, verification and welcome emails
|
|
366
|
+
automatically. See [Auth emails](https://somewhere.cloud/docs/sw.auth#auth-emails)
|
|
367
|
+
for app auth templates and Somewhere's own lifecycle emails.
|
|
368
|
+
On the platform address each project, and each account across all of its
|
|
369
|
+
projects, can send at most 30 auth emails per hour and 200 per day to people
|
|
370
|
+
who have not verified their address (`EMAIL_FIRST_CONTACT_LIMIT`, see
|
|
371
|
+
`sw.auth` → auth emails); a project's own verified domain has no such limit.
|
|
372
|
+
The rules in "Sending reputation" below apply to them.
|
|
373
|
+
|
|
374
|
+
### Attachments
|
|
375
|
+
|
|
376
|
+
Pass up to 3 small files as `attachments: [{ filename, content_type?, content }]`,
|
|
377
|
+
with `content` in base64. They can total at most 256 KB. The filename
|
|
378
|
+
extension must be one of `ics`, `pdf`, `png`, `jpg`, `jpeg`, `gif`, `webp`,
|
|
379
|
+
`csv`, `txt` or `json`. `content_type` defaults from the extension; for `.ics`
|
|
380
|
+
it is `text/calendar; charset=UTF-8; method=REQUEST`, so a calendar invite
|
|
381
|
+
shows its accept button in Gmail, Outlook and Apple Mail. A refused attachment
|
|
382
|
+
returns `VALIDATION_ERROR` naming the rule.
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
await sw.email.send({
|
|
386
|
+
to: booking.email,
|
|
387
|
+
subject: 'Your call is booked',
|
|
388
|
+
text: 'The invite is attached.',
|
|
389
|
+
attachments: [{ filename: 'invite.ics', content: btoa(icsText) }],
|
|
390
|
+
idempotency_key: `booked:${booking.id}`,
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Result and errors
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
// api/_lib/order-email-result.ts — read the result's status; a refused send throws
|
|
398
|
+
export async function sendOrderShippedOnce(
|
|
399
|
+
sw: SomewhereRuntimeContext,
|
|
400
|
+
order: { id: string; email: string; trackingNumber: string },
|
|
401
|
+
): Promise<{ id: string; status: SomewhereEmailSendResult['status']; replay: boolean }> {
|
|
402
|
+
const sent = await sw.email.send({
|
|
403
|
+
to: order.email,
|
|
404
|
+
subject: 'Your order shipped',
|
|
405
|
+
text: `Tracking: ${order.trackingNumber}`,
|
|
406
|
+
idempotency_key: `order-shipped:${order.id}`,
|
|
407
|
+
});
|
|
408
|
+
// → { id, tracking_id, message_id, status, duplicate?, sender?, test_inbox? }
|
|
409
|
+
return { id: sent.id, status: sent.status, replay: sent.duplicate === true };
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
A new send returns one of three `status` values:
|
|
414
|
+
- `sent`: the provider accepted the message. The call waits for that.
|
|
415
|
+
Accepted is not delivered.
|
|
416
|
+
- `pending`: that step was interrupted. Check `sw.email.status(id)`, or
|
|
417
|
+
resend only with the same `idempotency_key`.
|
|
418
|
+
- `captured`: the recipient is this project's own test address, so the
|
|
419
|
+
message was stored in the test inbox and not delivered (see "Test inbox"
|
|
420
|
+
below). The result has `test_inbox: { address, delivered: false }` and no
|
|
421
|
+
`tracking_id`.
|
|
422
|
+
|
|
423
|
+
Repeating an `idempotency_key` returns the stored result with
|
|
424
|
+
`duplicate: true` and the same `id`. Its `status` is that message's
|
|
425
|
+
current state: any of the three above, a later delivery state (`delivered`,
|
|
426
|
+
`opened`, `clicked`, `bounced`, `complained`), or `suppressed`,
|
|
427
|
+
`preference_blocked`, `delivery_unknown`, or `failed`. Check `status`,
|
|
428
|
+
not only that nothing threw. Do not gate follow-up work on
|
|
429
|
+
`status === 'sent'` alone: a captured test send and a replay of a delivered
|
|
430
|
+
message are both successful sends.
|
|
431
|
+
|
|
432
|
+
A message that is not sent THROWS an Error carrying `.code` and `.status`:
|
|
433
|
+
`MANAGED_SENDER_RECIPIENT_NOT_A_USER`, `EMAIL_SUPPRESSED`,
|
|
434
|
+
`RECIPIENT_UNDELIVERABLE_DOMAIN` (see "Sending reputation"),
|
|
435
|
+
`EMAIL_DAILY_LIMIT` / `EMAIL_MONTHLY_LIMIT` (422), `RATE_LIMITED` (429), or
|
|
436
|
+
`EMAIL_DELIVERY_UNKNOWN` (502 — acceptance unconfirmed; check
|
|
437
|
+
`sw.email.status(id)` or resend only with the same `idempotency_key`).
|
|
438
|
+
When the email is a side effect of work that already succeeded (a saved
|
|
439
|
+
row), catch the error and record it on that row instead of failing the
|
|
440
|
+
request — see https://somewhere.cloud/docs/recipe-signed-in-app.txt.
|
|
441
|
+
|
|
442
|
+
For the signed-in user's address, use
|
|
443
|
+
`const user = await sw.auth.requireUser(req)`, then `user.email`. To contact
|
|
444
|
+
other users, authorize the sending action in your function, then use
|
|
445
|
+
`sw.auth.server.listUsers({ ids })` for the permitted recipients' addresses.
|
|
446
|
+
For group contacts, check the caller's role and pass the IDs from
|
|
447
|
+
`sw.groups.members`; see `sw.auth` → **Member contacts** for a complete example.
|
|
448
|
+
Apply your app's recipient-consent rules and the sender requirements above.
|
|
449
|
+
For a fixed notification recipient such as the app owner, keep the configured
|
|
450
|
+
address in an env var.
|
|
451
|
+
|
|
452
|
+
## Sending to many recipients
|
|
453
|
+
|
|
454
|
+
Each send waits for its own result, so awaiting them one after another adds
|
|
455
|
+
up: five sends in a loop take about five times as long as one. Sends from
|
|
456
|
+
one handler can run at the same time. Start them together in groups of five
|
|
457
|
+
and give each its own `idempotency_key`, so a retried request never emails
|
|
458
|
+
anyone twice:
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
// api/_lib/send-round.ts — members come from your own records, never the request.
|
|
462
|
+
export interface Member { id: string; email: string }
|
|
463
|
+
export interface Round { id: string; subject: string; text: string }
|
|
464
|
+
|
|
465
|
+
/** Sends in groups of five; returns members whose send was refused or not confirmed. */
|
|
466
|
+
export async function sendRound(
|
|
467
|
+
sw: SomewhereRuntimeContext,
|
|
468
|
+
round: Round,
|
|
469
|
+
members: readonly Member[],
|
|
470
|
+
): Promise<{ id: string; code: string; email_id?: string }[]> {
|
|
471
|
+
const unsent: { id: string; code: string; email_id?: string }[] = [];
|
|
472
|
+
for (let i = 0; i < members.length; i += 5) {
|
|
473
|
+
await Promise.all(members.slice(i, i + 5).map(async (m) => {
|
|
474
|
+
try {
|
|
475
|
+
const sent = await sw.email.send({
|
|
476
|
+
to: m.email,
|
|
477
|
+
subject: round.subject,
|
|
478
|
+
text: round.text,
|
|
479
|
+
idempotency_key: `round-${round.id}-${m.id}`,
|
|
480
|
+
});
|
|
481
|
+
// pending: acceptance unconfirmed; check sw.email.status(sent.id) before any resend.
|
|
482
|
+
if (sent.status === 'pending') unsent.push({ id: m.id, code: 'PENDING', email_id: sent.id });
|
|
483
|
+
} catch (error) {
|
|
484
|
+
const code = error instanceof Error && 'code' in error ? String(error.code) : 'EMAIL_FAILED';
|
|
485
|
+
unsent.push({ id: m.id, code });
|
|
486
|
+
}
|
|
487
|
+
}));
|
|
488
|
+
}
|
|
489
|
+
return unsent;
|
|
490
|
+
}
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
Five at once finish in about the time of one. The send rate limit still
|
|
494
|
+
applies: about 60 sends a minute for the account that owns the project,
|
|
495
|
+
shared by all of its projects. Above that a send throws `RATE_LIMITED`
|
|
496
|
+
(429). Your plan's email allowance applies too. For larger lists, or when the
|
|
497
|
+
caller should not wait, run the fan-out in a job (`sw.jobs`), one job per batch of recipients.
|
|
498
|
+
|
|
499
|
+
## Test inbox
|
|
500
|
+
|
|
501
|
+
Addresses `<anything>@<project-subdomain>.test.somewhere.site` never reach a
|
|
502
|
+
real mailbox. Mail to this project's own test addresses is stored in its test
|
|
503
|
+
inbox instead. That covers both kinds of mail:
|
|
504
|
+
- the project's AUTH email (verification, magic link, password reset): sign
|
|
505
|
+
up with a test address, then read the inbox;
|
|
506
|
+
- your own `sw.email.send` to that address. It returns `status: 'captured'`
|
|
507
|
+
with `test_inbox: { address, delivered: false }` and no `tracking_id`.
|
|
508
|
+
With the platform-managed sender, the address must belong to one of this
|
|
509
|
+
project's users (for example, one who signed up with it, verified or not) or
|
|
510
|
+
the owner. Otherwise the send is refused with
|
|
511
|
+
`MANAGED_SENDER_RECIPIENT_NOT_A_USER`.
|
|
512
|
+
|
|
513
|
+
Read it with `somewhere email test-inbox <address>` (or
|
|
514
|
+
`sw.email.inbox(address)`) →
|
|
515
|
+
`{ address, messages: [{ id, to, subject, text, html, magic_link, verification_code, attachments, created_at }] }`,
|
|
516
|
+
where `attachments` is `[{ filename, content_type, content }]` (base64, empty when none).
|
|
517
|
+
`verification_code` is the code an auth message carries (the 6-digit email
|
|
518
|
+
verification or sign-in code), or `null`. A verified test user therefore
|
|
519
|
+
takes three calls and no HTML parsing: sign up with a test address, read
|
|
520
|
+
`messages[0].verification_code`, then verify with it
|
|
521
|
+
(`POST /api/auth/verify-email { code }` in the app's session). Verification
|
|
522
|
+
is the real flow; only the mailbox is a test one.
|
|
523
|
+
A captured send does not appear in `sw.email.history()` or the project's
|
|
524
|
+
sent-email list, and it does not count toward the email allowance. Repeating
|
|
525
|
+
its `idempotency_key` returns the same `id` with `duplicate: true` and
|
|
526
|
+
stores no second copy. Captures are kept for 7 days, up to 500 messages or
|
|
527
|
+
10 MiB per project; beyond that a send throws `TEST_INBOX_FULL` (422) with the
|
|
528
|
+
time the oldest capture expires.
|
|
529
|
+
|
|
530
|
+
A test address that belongs to ANOTHER project is refused:
|
|
531
|
+
`sw.email.send` throws `EMAIL_TEST_ADDRESS_NOT_OWNED` (422), and reading
|
|
532
|
+
its inbox fails with `VALIDATION_ERROR`. A send to any other domain is an
|
|
533
|
+
ordinary real send. `status: 'sent'` means the provider accepted the
|
|
534
|
+
message, not that it was delivered. To prove delivery, send to a real mailbox
|
|
535
|
+
you can read, or check the delivery events from `sw.email.status(id)`.
|
|
536
|
+
|
|
537
|
+
## Sending reputation
|
|
538
|
+
|
|
539
|
+
Every project shares the platform's sending reputation, so these rules apply
|
|
540
|
+
to all mail, including the auth emails the platform sends for you. Each
|
|
541
|
+
refusal is a typed event in the project's logs (`data.code`).
|
|
542
|
+
|
|
543
|
+
- Reserved domains are never sent to. An address at example.com, example.net,
|
|
544
|
+
example.org or any subdomain of them, or ending in .example, .test,
|
|
545
|
+
.invalid, .localhost or .local, cannot receive mail. An auth email
|
|
546
|
+
(verification, magic link, password reset, welcome) to such an address is
|
|
547
|
+
held in this project's test inbox under that exact address, so you can
|
|
548
|
+
still read the code or link: `somewhere email test-inbox alice@example.com`.
|
|
549
|
+
Your own `sw.email.send` to one throws `RECIPIENT_UNDELIVERABLE_DOMAIN`.
|
|
550
|
+
Log event: `RECIPIENT_UNDELIVERABLE_DOMAIN` (`test_inbox: true` when held).
|
|
551
|
+
Use a test inbox address for automated sign-ups.
|
|
552
|
+
- The platform does not send to app addresses. An address at an app's
|
|
553
|
+
own host, such as `anyone@<subdomain>.somewhere.site` (any name under
|
|
554
|
+
somewhere.site, or under any other app-host domain the platform owns), is
|
|
555
|
+
not given a mailbox, so mail to it is refused before delivery and is not
|
|
556
|
+
held in the test inbox. Its code or link is not delivered or stored in the
|
|
557
|
+
test inbox. Requests that report the send answer `EMAIL_SUPPRESSED` (422):
|
|
558
|
+
a magic link, an invitation, a requested verification code and an email
|
|
559
|
+
sign-in code. Requests that send in the background keep their usual answer:
|
|
560
|
+
a password reset still answers 200 for every address, and sign-up still
|
|
561
|
+
succeeds while its welcome and verification emails are refused. Either way
|
|
562
|
+
the refusal is in the project's logs. `sw.email.send` throws
|
|
563
|
+
`RECIPIENT_UNDELIVERABLE_DOMAIN`. Log event:
|
|
564
|
+
`RECIPIENT_UNDELIVERABLE_DOMAIN` with `reason: 'platform_app_host'`.
|
|
565
|
+
The test inbox (`@<subdomain>.test.somewhere.site`) and the platform's own
|
|
566
|
+
addresses at somewhere.site and somewhere.cloud are not affected. Any
|
|
567
|
+
other domain is sent normally; the platform does not look up whether it
|
|
568
|
+
accepts mail.
|
|
569
|
+
- Bounces and spam complaints stop further sends to that address. A permanent
|
|
570
|
+
bounce pauses it for 30 days, a temporary one (such as a full mailbox) for
|
|
571
|
+
24 hours, and a spam complaint permanently. The log event is
|
|
572
|
+
`EMAIL_RECIPIENT_SUPPRESSED` with `reason` (`bounce`, `soft_bounce`,
|
|
573
|
+
`complaint`) and `expires_at`. A send to a paused address is refused
|
|
574
|
+
before delivery with `EMAIL_SUPPRESSED` (422 for auth email) and logged
|
|
575
|
+
as `EMAIL_SUPPRESSED`.
|
|
576
|
+
- Password resets, magic links and verification emails do not consume your
|
|
577
|
+
plan's email allowance and still send when ordinary email has used it up.
|
|
578
|
+
Recipient suppression and sign-in abuse protections remain in force. Welcome
|
|
579
|
+
mail and `sw.email.send` use the regular allowance shown by
|
|
580
|
+
`limits.emails_per_day` and `limits.emails_per_month` in /v1/pricing.
|
|
581
|
+
Messages captured in the test inbox use no email allowance.
|
|
582
|
+
- A project whose own mail bounces or is reported as spam too often is paused.
|
|
583
|
+
Over a rolling 24 hours, once it has sent at least 50 messages, 5% permanent
|
|
584
|
+
bounces or 0.1% spam reports (and at least 3 of either) pauses the project's
|
|
585
|
+
sending: every send, auth email included, answers `EMAIL_PROJECT_PAUSED`
|
|
586
|
+
(auth endpoints 503, `sw.email.send` 422) and nothing reaches a mailbox.
|
|
587
|
+
Test inbox addresses keep working. The owner gets one email and the log event
|
|
588
|
+
`EMAIL_PROJECT_PAUSED`; sending resumes on its own once the rate recovers
|
|
589
|
+
(log event `EMAIL_PROJECT_RESUMED`). Check the state with
|
|
590
|
+
`email_reputation({ project_id })`.
|
|
591
|
+
- **Mail from the platform's shared address** also pauses on counts, whatever
|
|
592
|
+
the volume: 2 spam reports or 5 permanent bounces of that mail in
|
|
593
|
+
24 hours (`reason`: `complaint_count`,
|
|
594
|
+
`bounce_count`). This pause stops only the project's mail from the shared
|
|
595
|
+
address; mail from its own verified domain continues. It resumes on its own
|
|
596
|
+
once the last 24 hours are back under both
|
|
597
|
+
counts. A message's bounce or complaint is counted once.
|
|
598
|
+
- **Scope:** one spam complaint alone does not pause a project; it stops mail to
|
|
599
|
+
that one address. A rate pause or a manual pause covers real delivery from
|
|
600
|
+
the project, including sign-in emails and mail from your own sender domain.
|
|
601
|
+
Test inboxes remain available.
|
|
602
|
+
- **The platform can pause a project by hand** (`reason`: `manual`). The owner
|
|
603
|
+
gets the same email. A manual pause does not lift on its own; only the
|
|
604
|
+
platform team resumes it.
|
|
605
|
+
- **No resume button.** While delivery is paused, older events leave the
|
|
606
|
+
rolling window. The platform rechecks paused projects and resumes sending
|
|
607
|
+
when the reputation threshold clears. Reduce future complaints with an opt-out
|
|
608
|
+
link in every mailing and by skipping `sw.email.bounces()`
|
|
609
|
+
addresses.
|
|
610
|
+
|
|
611
|
+
## Delivery health (scrub bounces before sending)
|
|
612
|
+
|
|
613
|
+
The email provider posts bounce + complaint webhooks; the platform records
|
|
614
|
+
every event on the project automatically. Two MCP tools expose them:
|
|
615
|
+
|
|
616
|
+
- email_events_list({ project_id, limit?, offset? }) — recent sends
|
|
617
|
+
with their latest event (sent | delivered | opened | clicked |
|
|
618
|
+
bounced | complained | delivery_delayed). Build an audit view or
|
|
619
|
+
spot a bounce spike after a blast.
|
|
620
|
+
|
|
621
|
+
- email_bounces_list({ project_id, days?, limit? }) — deduplicated
|
|
622
|
+
recipients that bounced or complained inside the window
|
|
623
|
+
(default 30 days, max 365). One row per address with last_status,
|
|
624
|
+
last_at, occurrences.
|
|
625
|
+
|
|
626
|
+
From INSIDE a function, scrub before you send (no MCP round-trip):
|
|
627
|
+
- `sw.email.checkSuppression(address)` → `{ address, suppressed, status, last_at, occurrences }` — is this ONE recipient dead (bounced or complained)? Check it before `sw.email.send`.
|
|
628
|
+
- `sw.email.bounces({ days?, limit? })` → `{ bounces, window_days, limit }`.
|
|
629
|
+
The `bounces` array contains the dead-address rows; the other fields report
|
|
630
|
+
the effective query window and cap.
|
|
631
|
+
|
|
632
|
+
For a single message's full timeline use email_status({ id }).
|
|
633
|
+
|
|
634
|
+
## Delivery and engagement events
|
|
635
|
+
|
|
636
|
+
Every message sent through sw.email records delivery, open, and click events
|
|
637
|
+
when the recipient's inbox reports them. Recent-message lists include sent,
|
|
638
|
+
delivered, opened, and clicked counts; email_status returns the full timeline
|
|
639
|
+
for one tracking id. Opens are approximate because some inboxes block images.
|
|
640
|
+
|
|
641
|
+
**Before every send loop, scrub against email_bounces_list.**
|
|
642
|
+
Mailing a dead address repeatedly is the single fastest way to land
|
|
643
|
+
your verified domain in a spam folder. Inside a function, skip the addresses
|
|
644
|
+
in the returned list first. That list is bounded; every send also checks the
|
|
645
|
+
address's current suppression status:
|
|
646
|
+
|
|
647
|
+
```ts
|
|
648
|
+
// api/_lib/send-to-reachable.ts
|
|
649
|
+
import { sendRound, type Member, type Round } from './send-round';
|
|
650
|
+
|
|
651
|
+
/** Skips addresses in the returned recent bounce list, then sends. */
|
|
652
|
+
export async function sendToReachable(
|
|
653
|
+
sw: SomewhereRuntimeContext,
|
|
654
|
+
round: Round,
|
|
655
|
+
members: readonly Member[],
|
|
656
|
+
): Promise<{ id: string; code: string; email_id?: string }[]> {
|
|
657
|
+
const { bounces } = await sw.email.bounces({ days: 60, limit: 1000 });
|
|
658
|
+
const bounced = new Set(bounces.map((row) => row.address.toLowerCase()));
|
|
659
|
+
return sendRound(sw, round, members.filter((m) => !bounced.has(m.email.toLowerCase())));
|
|
660
|
+
}
|
|
661
|
+
```
|