diff --git a/.env.example b/.env.example index ac1e492..8efd89a 100644 --- a/.env.example +++ b/.env.example @@ -20,6 +20,10 @@ REDIS_URL=redis://localhost:6379 # Optional: Spamhaus Data Query Service key. Public DNSBL queries from cloud resolvers are refused, so blacklist checks report "unknown" without it. SPAMHAUS_DQS_KEY= +# Optional: token (16+ chars) that status-page monitors send as "Authorization: Bearer " +# to get full detail from /api/health/ses. Without it the endpoint returns status only. +HEALTH_CHECK_TOKEN= + # Development only: print every SQL query Prisma runs (very noisy). # PRISMA_LOG_QUERIES=true diff --git a/.github/README.md b/.github/README.md index a02c50c..9564c62 100644 --- a/.github/README.md +++ b/.github/README.md @@ -16,13 +16,14 @@ Docs · API reference · Releases · - Discord + Status · + Discord

License: AGPL-3.0 Latest release - Discord + Discord

--- diff --git a/.github/SUPPORT.md b/.github/SUPPORT.md index 9a12140..7c34771 100644 --- a/.github/SUPPORT.md +++ b/.github/SUPPORT.md @@ -4,8 +4,9 @@ Need help with ByteSend? ## Community Support -- Discord: https://https://discord.gg/C2Q4GHXKQA +- Discord: https://discord.gg/C2Q4GHXKQA - Docs: https://docs.bytesend.cloud +- Service status: https://status.bytesend.cloud ## Commercial / Cloud Support @@ -16,4 +17,4 @@ Need help with ByteSend? Do not open public issues for vulnerabilities. - See `SECURITY.md` -- Email: support@nodebyte.co.uk +- Email: security@nodebyte.co.uk diff --git a/.gitignore b/.gitignore index d7a95f0..a5b1c06 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ node_modules .env.selfhost .docs .docker +apps/status # Testing coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index 51b3756..7933575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [0.4.1] - 2026-10-19 + +### Added +- **SES health endpoints** for status-page monitoring: `GET /api/health/ses/` returns 200 while a region can send (with `status` of `operational` or `degraded` — sandboxed, on probation or above 90% of the 24-hour quota) and 503 when sending is disabled, the account is shut down or SES can't be reached; `GET /api/health/ses` summarises every active region. Results are cached for a minute, and enforcement and quota details are only returned to requests carrying the optional `HEALTH_CHECK_TOKEN` +- **Status links** — the dashboard sidebar, docs navigation, README and support page now link to [status.bytesend.cloud](https://status.bytesend.cloud) +- **[Examples](https://docs.bytesend.cloud/get-started/examples)** — complete, runnable examples for Node.js, TypeScript, React Email (TypeScript and JavaScript), Next.js, Express, idempotent and batch sends, Python and Go, replacing links to an examples repository that no longer exists +- The React Email guide now passes components straight to the SDK's `react` option instead of rendering them by hand + +### Fixed +- Broken Discord links (`https://https://…`) in the docs navigation, docs introduction, self-hosting overview, README and support page +- The support page now lists `security@nodebyte.co.uk` for vulnerability reports, matching the security policy +- Emails move to `SENT` as soon as SES accepts them instead of staying `QUEUED` until SES's first event arrives +- SES callbacks from an unrecognised SNS topic are now logged in production; previously they were dropped silently, leaving statuses, bounces and complaints unprocessed +- Removed a per-email Stripe call that always failed (it used the meter-event *adjustment* API); usage continues to be reported by the daily usage job +- Docker Compose files now pass `SPAMHAUS_DQS_KEY` (and `ADMIN_DISCORD_WEBHOOK_URL` / `DISCORD_WEBHOOK_URL`) through to the app, so blocklist checks and platform alerts can use them +- Admin navigation no longer overlaps on narrow screens + +--- + ## [0.4.0] - 2026-10-18 ### Added diff --git a/apps/docs/docs.json b/apps/docs/docs.json index 91ecae8..c24ed1c 100644 --- a/apps/docs/docs.json +++ b/apps/docs/docs.json @@ -36,7 +36,8 @@ "get-started/nodejs", "get-started/python", "get-started/local", - "get-started/smtp" + "get-started/smtp", + "get-started/examples" ] } ] @@ -206,7 +207,7 @@ }, { "anchor": "Discord", - "href": "https://https://discord.gg/C2Q4GHXKQA", + "href": "https://discord.gg/C2Q4GHXKQA", "icon": "discord" }, { @@ -234,9 +235,13 @@ }, "navbar": { "links": [ + { + "label": "Status", + "href": "https://status.bytesend.cloud" + }, { "label": "Support", - "href": "https://https://discord.gg/C2Q4GHXKQA" + "href": "https://discord.gg/C2Q4GHXKQA" } ], "primary": { @@ -248,7 +253,8 @@ "footer": { "socials": { "x": "https://x.com/TryByteSend", - "github": "https://github.com/NodeByteLTD/ByteSend" + "github": "https://github.com/NodeByteLTD/ByteSend", + "discord": "https://discord.gg/C2Q4GHXKQA" } }, "contextual": { diff --git a/apps/docs/get-started/examples.mdx b/apps/docs/get-started/examples.mdx new file mode 100644 index 0000000..8969549 --- /dev/null +++ b/apps/docs/get-started/examples.mdx @@ -0,0 +1,422 @@ +--- +title: Examples +description: "Complete, copy-paste examples for sending email with ByteSend from Node.js, TypeScript, React Email, Next.js, Express, Python and Go" +icon: code +--- + +Every example below is a complete project you can run as-is. Each one needs: + +- A [ByteSend API key](https://bytesend.cloud/dev-settings/api-keys), exported as `BYTESEND_API_KEY` +- A [verified domain](https://bytesend.cloud/domains) to send from + +The SDKs read `BYTESEND_API_KEY` from the environment automatically, so you don't need to pass it in code. + +--- + +## Node.js + +```json package.json +{ + "type": "module", + "dependencies": { + "bytesend-js": "latest" + } +} +``` + +```js send.js +import { ByteSend } from "bytesend-js"; + +const bytesend = new ByteSend(); + +const { data, error } = await bytesend.emails.send({ + from: "Acme ", + to: "customer@example.com", + subject: "Welcome to Acme", + html: "

Thanks for signing up!

", + text: "Thanks for signing up!", +}); + +if (error) { + console.error("Send failed:", error); + process.exit(1); +} + +console.log("Queued email", data.emailId); +``` + +```sh +npm install +node send.js +``` + + +SDK methods return `{ data, error }` instead of throwing, so always check `error` before using `data`. + + +--- + +## TypeScript + +```json package.json +{ + "type": "module", + "scripts": { + "send": "tsx send.ts" + }, + "dependencies": { + "bytesend-js": "latest" + }, + "devDependencies": { + "tsx": "latest", + "typescript": "latest" + } +} +``` + +```ts send.ts +import { ByteSend } from "bytesend-js"; + +const bytesend = new ByteSend(); + +const { data, error } = await bytesend.emails.send({ + from: "Acme ", + to: ["customer@example.com"], + subject: "Your receipt", + html: "

Thanks for your order.

", + replyTo: "billing@acme.com", +}); + +if (error) throw new Error(error.message); +console.log("Queued email", data?.emailId); +``` + +```sh +npm install +npm run send +``` + +--- + +## React Email (TypeScript) + +Pass a React Email component as `react` and the SDK renders it to HTML for you — no separate render step needed. + +```json package.json +{ + "type": "module", + "scripts": { + "send": "tsx send.tsx" + }, + "dependencies": { + "bytesend-js": "latest", + "@react-email/components": "latest", + "react": "latest" + }, + "devDependencies": { + "@types/react": "latest", + "tsx": "latest", + "typescript": "latest" + } +} +``` + +```json tsconfig.json +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "Bundler", + "jsx": "react-jsx", + "strict": true, + "skipLibCheck": true + } +} +``` + +```tsx emails/welcome.tsx +import { Body, Button, Container, Heading, Html, Text } from "@react-email/components"; + +export function WelcomeEmail({ name, url }: { name: string; url: string }) { + return ( + + + + Welcome, {name}! + Your account is ready. + + + + + ); +} +``` + +```tsx send.tsx +import { ByteSend } from "bytesend-js"; +import { WelcomeEmail } from "./emails/welcome"; + +const bytesend = new ByteSend(); + +const { data, error } = await bytesend.emails.send({ + from: "Acme ", + to: "customer@example.com", + subject: "Welcome to Acme", + react: , +}); + +if (error) throw new Error(error.message); +console.log("Queued email", data?.emailId); +``` + +```sh +npm install +npm run send +``` + + +`react` isn't supported in `emails.batch()`. For batch sends, render each email first with `render()` from `@react-email/components` and pass the result as `html`. + + +--- + +## React Email (JavaScript) + +The same project without TypeScript. `tsx` runs `.jsx` files directly, so no Babel setup is needed. + +```json package.json +{ + "type": "module", + "scripts": { + "send": "tsx send.jsx" + }, + "dependencies": { + "bytesend-js": "latest", + "@react-email/components": "latest", + "react": "latest" + }, + "devDependencies": { + "tsx": "latest" + } +} +``` + +```jsx emails/welcome.jsx +import { Body, Button, Container, Heading, Html, Text } from "@react-email/components"; + +export function WelcomeEmail({ name, url }) { + return ( + + + + Welcome, {name}! + Your account is ready. + + + + + ); +} +``` + +```jsx send.jsx +import { ByteSend } from "bytesend-js"; +import { WelcomeEmail } from "./emails/welcome.jsx"; + +const bytesend = new ByteSend(); + +const { data, error } = await bytesend.emails.send({ + from: "Acme ", + to: "customer@example.com", + subject: "Welcome to Acme", + react: , +}); + +if (error) throw new Error(error.message); +console.log("Queued email", data.emailId); +``` + +--- + +## Next.js (App Router) + +Send from a route handler, and receive [webhooks](/guides/webhooks) in another. Keep your API key on the server — never import the SDK in a client component. + +```ts app/api/welcome/route.ts +import { ByteSend } from "bytesend-js"; + +const bytesend = new ByteSend(); + +export async function POST(request: Request) { + const { email } = (await request.json()) as { email: string }; + + const { data, error } = await bytesend.emails.send({ + from: "Acme ", + to: email, + subject: "Welcome to Acme", + html: "

Thanks for signing up!

", + }); + + if (error) { + return Response.json({ error: error.message }, { status: 502 }); + } + return Response.json({ emailId: data?.emailId }); +} +``` + +```ts app/api/bytesend-webhook/route.ts +import { Webhooks } from "bytesend-js"; + +const webhooks = new Webhooks(process.env.BYTESEND_WEBHOOK_SECRET!); + +export async function POST(request: Request) { + // Verify against the raw body — parsing JSON first breaks the signature. + const rawBody = await request.text(); + + try { + const event = webhooks.constructEvent(rawBody, { headers: request.headers }); + + if (event.type === "email.bounced") { + // Mark the address as undeliverable in your own database + } + + return new Response("ok"); + } catch (error) { + return new Response((error as Error).message, { status: 400 }); + } +} +``` + +--- + +## Express + +```ts server.ts +import express from "express"; +import { ByteSend, Webhooks } from "bytesend-js"; + +const bytesend = new ByteSend(); +const webhooks = new Webhooks(process.env.BYTESEND_WEBHOOK_SECRET!); +const app = express(); + +app.post("/welcome", express.json(), async (req, res) => { + const { data, error } = await bytesend.emails.send({ + from: "Acme ", + to: req.body.email, + subject: "Welcome to Acme", + html: "

Thanks for signing up!

", + }); + + if (error) return res.status(502).json({ error: error.message }); + res.json({ emailId: data?.emailId }); +}); + +// The webhook route needs the raw body for signature verification. +app.post("/bytesend-webhook", express.raw({ type: "application/json" }), (req, res) => { + try { + const event = webhooks.constructEvent(req.body, { headers: req.headers }); + if (event.type === "email.complained") { + // Stop emailing this recipient + } + res.send("ok"); + } catch (error) { + res.status(400).send((error as Error).message); + } +}); + +app.listen(3000); +``` + +--- + +## Safe retries and batches + +Pass an idempotency key to make retries safe: sending the same payload with the same key returns the original response instead of sending twice. + +```ts +await bytesend.emails.send( + { + from: "Acme ", + to: "customer@example.com", + subject: "Your receipt", + html: "

Order #1042

", + }, + { idempotencyKey: "receipt-1042" }, +); + +await bytesend.emails.batch( + [ + { from: "Acme ", to: "a@example.com", subject: "Hello A", html: "

Hi A

" }, + { from: "Acme ", to: "b@example.com", subject: "Hello B", html: "

Hi B

" }, + ], + { idempotencyKey: "welcome-batch-7" }, +); +``` + +--- + +## Python + +```sh +pip install bytesend +``` + +```python send.py +from bytesend import ByteSend + +client = ByteSend() # reads BYTESEND_API_KEY + +resp, _ = client.emails.send(payload={ + "from": "Acme ", + "to": "customer@example.com", + "subject": "Welcome to Acme", + "html": "

Thanks for signing up!

", +}) + +print("Queued email", resp["emailId"]) +``` + +See the [Python guide](/get-started/python) for error handling, idempotency and batches. + +--- + +## Go + +```sh +go get github.com/nodebyteltd/bytesend-go +``` + +```go main.go +package main + +import ( + "context" + "fmt" + "log" + + bytesend "github.com/nodebyteltd/bytesend-go" +) + +func main() { + client, err := bytesend.NewClient("") // empty key reads BYTESEND_API_KEY + if err != nil { + log.Fatal(err) + } + + resp, err := client.Emails.Create(context.Background(), bytesend.SendEmailPayload{ + From: "Acme ", + To: []string{"customer@example.com"}, + Subject: "Welcome to Acme", + HTML: "

Thanks for signing up!

", + }) + if err != nil { + log.Fatal(err) + } + + fmt.Println("Queued email", resp.EmailID) +} +``` + +See the [Go guide](/get-started/go) for the full client. diff --git a/apps/docs/guides/use-with-react-email.mdx b/apps/docs/guides/use-with-react-email.mdx index 38c7556..539430a 100644 --- a/apps/docs/guides/use-with-react-email.mdx +++ b/apps/docs/guides/use-with-react-email.mdx @@ -11,82 +11,83 @@ description: "A guide on how to use ByteSend with React Email" ```sh npm - npm install bytesend-js @react-email/render + npm install bytesend-js @react-email/components react ``` ```sh yarn -yarn add bytesend-js @react-email/render +yarn add bytesend-js @react-email/components react ``` ```sh pnpm -pnpm add bytesend-js @react-email/render +pnpm add bytesend-js @react-email/components react ``` ```sh bun -bun add bytesend-js @react-email/render +bun add bytesend-js @react-email/components react ``` ## Create an email template -```tsx -import * as React from "react"; -import { Html } from "@react-email/html"; -import { Button } from "@react-email/button"; - -export function Email(props) { - const { url } = props; +```tsx emails/welcome.tsx +import { Button, Html } from "@react-email/components"; +export function WelcomeEmail({ url }: { url: string }) { return ( - + ); } ``` -## Send an email using ByteSend +## Send it with ByteSend + +Pass the component as `react`. The SDK renders it to HTML for you, so there's no separate render step. -```ts +```tsx send.tsx import { ByteSend } from "bytesend-js"; -import { render } from "@react-email/render"; -import { Email } from "./email"; +import { WelcomeEmail } from "./emails/welcome"; const bytesend = new ByteSend("bs_your_bytesend_api_key"); - const html = await render(); - -const response = await bytesend.emails.send({ - to: "hello@bytesend.cloud", - from: "hello@bytesend.cloud", - subject: "ByteSend email", - html, +const { data, error } = await bytesend.emails.send({ + from: "Acme ", + to: "customer@example.com", + subject: "Welcome to Acme", + react: , }); ``` -## Build your project + +`react` isn't supported in `emails.batch()`. For batches, render each email with `render()` from `@react-email/components` and pass the result as `html`. + -### JavaScript +## Run it -If you're using nodejs, importing `email.jsx` might fail. make sure to add these to your babel config: +### TypeScript + +Set `"jsx": "react-jsx"` in your `tsconfig.json`, then run the file with [`tsx`](https://tsx.is): -```js +```json tsconfig.json { - "plugins": ["@babel/plugin-proposal-class-properties"] + "compilerOptions": { "jsx": "react-jsx" } } ``` -Checkout this [example](https://github.com/NodeByteHosting/bytesend-js-examples/tree/main/react-email-js) +```sh +npx tsx send.tsx +``` -### TypeScript +See the complete [React Email TypeScript example](/get-started/examples#react-email-typescript). -Just add `jsx` to your `tsconfig.json` +### JavaScript -```json -{ - "compilerOptions": { "jsx": "react-jsx" } -} +Use `.jsx` files and run them with `tsx` — it handles JSX without any Babel configuration: + +```sh +npx tsx send.jsx ``` -Checkout this [example](https://github.com/NodeByteHosting/bytesend-js-examples/tree/main/react-email-ts) +See the complete [React Email JavaScript example](/get-started/examples#react-email-javascript). diff --git a/apps/docs/introduction.mdx b/apps/docs/introduction.mdx index 7490d8c..13496df 100644 --- a/apps/docs/introduction.mdx +++ b/apps/docs/introduction.mdx @@ -277,7 +277,7 @@ Want to run ByteSend on your own infrastructure? ## Quick Links - [View GitHub Repository](https://github.com/NodeByteLTD/ByteSend) -- [Join Community Discord](https://https://discord.gg/C2Q4GHXKQA) +- [Join Community Discord](https://discord.gg/C2Q4GHXKQA) - [Follow on Twitter](https://twitter.com/TryByteSend) - [Dashboard](https://bytesend.cloud) @@ -285,5 +285,5 @@ Want to run ByteSend on your own infrastructure? - Browse the [API Reference](/api-reference/introduction) - Check out [Integration Guides](/guides/webhooks) -- Join our [Community Discord](https://https://discord.gg/C2Q4GHXKQA) +- Join our [Community Discord](https://discord.gg/C2Q4GHXKQA) - View [GitHub Discussions](https://github.com/NodeByteLTD/ByteSend/discussions) diff --git a/apps/docs/self-hosting/overview.mdx b/apps/docs/self-hosting/overview.mdx index 09799be..353df26 100644 --- a/apps/docs/self-hosting/overview.mdx +++ b/apps/docs/self-hosting/overview.mdx @@ -8,7 +8,7 @@ ByteSend is fully self-hostable. This guide covers two deployment paths: - **[Docker (recommended)](#docker-deployment)** — spin up the entire stack with a single `docker compose` command - **[Manual / bare-metal](#manual-deployment)** — install directly on a Linux server using Node.js and pnpm -If you have questions, join [#self-host](https://https://discord.gg/C2Q4GHXKQA) on Discord. +If you have questions, join [#self-host](https://discord.gg/C2Q4GHXKQA) on Discord. --- diff --git a/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx b/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx index 45f13ee..fcc7277 100644 --- a/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx +++ b/apps/web/src/app/(dashboard)/admin/_components/admin-nav.tsx @@ -84,7 +84,7 @@ export function AdminNav({ isAdmin }: { isAdmin: boolean }) {