Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

---

## [0.9.1] - 2026-10-21

### Added
- **Receiving on the stats page**: emails received, DMARC reports read and the messages they covered over the last 30 days, with a daily chart
- **Receiving health check** at `/api/health/inbound` for status pages. A test email is sent to a hosted address every 10 minutes, so the check covers the whole receiving path, along with the receipt rule and the processing queue

### Fixed
- The website no longer stops responding to taps on phones while the homepage loads. Code samples are now highlighted on the server instead of in the browser

---

## [0.9.0] - 2026-10-20

### Added
Expand Down Expand Up @@ -1044,7 +1055,8 @@ Initial public beta release of ByteSend: an all-in-one email infrastructure plat

---

[Unreleased]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.0...HEAD
[Unreleased]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.1...HEAD
[0.9.1]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/ByteSendApp/ByteSend/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/ByteSendApp/ByteSend/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/ByteSendApp/ByteSend/compare/v0.6.0...v0.7.0
Expand Down
49 changes: 37 additions & 12 deletions apps/web/src/app/(marketing)/stats/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const dynamic = "force-dynamic";

export const metadata: Metadata = {
title: "Open stats – ByteSend",
description: "Live, aggregate numbers from ByteSend: emails sent, delivery rate, deliverability health and uptime.",
description: "Live, aggregate numbers from ByteSend: emails sent and received, delivery rate, deliverability health and uptime.",
alternates: { canonical: "https://bytesend.cloud/stats" },
};

Expand Down Expand Up @@ -47,23 +47,25 @@ function StatTile({ value, label, hint }: { value: string; label: string; hint?:
);
}

function VolumeChart({ days }: { days: PublicStatsDay[] }) {
const max = Math.max(1, ...days.map((day) => day.sent));
function VolumeChart({ days, metric = "sent" }: { days: PublicStatsDay[]; metric?: "sent" | "received" }) {
const gradientId = `stats-bar-${metric}`;
const max = Math.max(1, ...days.map((day) => day[metric]));
const width = 600;
const height = 160;
const gap = 4;
const barWidth = (width - gap * (days.length - 1)) / days.length;

return (
<svg viewBox={`0 0 ${width} ${height}`} className="h-40 w-full" preserveAspectRatio="none" role="img" aria-label="Emails sent per day over the last 30 days">
<svg viewBox={`0 0 ${width} ${height}`} className="h-40 w-full" preserveAspectRatio="none" role="img" aria-label={`Emails ${metric} per day over the last 30 days`}>
<defs>
<linearGradient id="stats-bar" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor="#1fb5ff" />
<stop offset="100%" stopColor="#0057ff" />
<linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor={metric === "sent" ? "#1fb5ff" : "#85fcff"} />
<stop offset="100%" stopColor={metric === "sent" ? "#0057ff" : "#00c3d6"} />
</linearGradient>
</defs>
{days.map((day, index) => {
const barHeight = day.sent === 0 ? 2 : Math.max(3, (day.sent / max) * height);
const value = day[metric];
const barHeight = value === 0 ? 2 : Math.max(3, (value / max) * height);
return (
<rect
key={day.date}
Expand All @@ -72,10 +74,10 @@ function VolumeChart({ days }: { days: PublicStatsDay[] }) {
width={barWidth}
height={barHeight}
rx={2}
fill={day.sent === 0 ? "currentColor" : "url(#stats-bar)"}
className={day.sent === 0 ? "text-border" : undefined}
fill={value === 0 ? "currentColor" : `url(#${gradientId})`}
className={value === 0 ? "text-border" : undefined}
>
<title>{`${formatDay(day.date)}: ${full.format(day.sent)} sent`}</title>
<title>{`${formatDay(day.date)}: ${full.format(value)} ${metric}`}</title>
</rect>
);
})}
Expand Down Expand Up @@ -166,6 +168,28 @@ export default async function StatsPage() {
</div>
</Reveal>

<Reveal>
<div className="flex flex-wrap items-baseline justify-between gap-2">
<h2 className="text-lg font-semibold tracking-tight">Receiving</h2>
<span className="text-xs text-muted-foreground">Last {window.days} days (UTC)</span>
</div>
<p className="mt-1 text-sm text-muted-foreground">
Mail arriving at ByteSend inboxes, and the DMARC reports we read for teams&apos; domains.
</p>
<div className="mt-4 grid grid-cols-1 gap-px overflow-hidden rounded-lg border border-border bg-border sm:grid-cols-3">
<StatTile value={formatCount(stats.inbound.received)} label="Emails received" hint={`Last ${window.days} days`} />
<StatTile value={formatCount(stats.inbound.dmarcReports)} label="DMARC reports read" hint={`Last ${window.days} days`} />
<StatTile value={formatCount(stats.inbound.dmarcMessages)} label="Messages covered by reports" hint="Checked against SPF and DKIM" />
</div>
<div className="mt-4 rounded-lg border border-border bg-card p-5">
<VolumeChart days={stats.daily} metric="received" />
<div className="mt-3 flex justify-between text-xs text-muted-foreground">
<span>{formatDay(stats.daily[0]!.date)}</span>
<span>{formatDay(stats.daily[stats.daily.length - 1]!.date)}</span>
</div>
</div>
</Reveal>

<div className="grid grid-cols-1 gap-12 lg:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]">
<Reveal>
<h2 className="text-lg font-semibold tracking-tight">Deliverability health</h2>
Expand Down Expand Up @@ -212,7 +236,8 @@ export default async function StatsPage() {

<p className="border-t border-border pt-8 text-xs leading-relaxed text-muted-foreground">
Figures combine transactional and marketing email across all ByteSend Cloud teams. Self-hosted instances are not
included. Rates are calculated against emails sent in the window; days are in UTC.
included. Rates are calculated against emails sent in the window; days are in UTC. Received email counts mail kept
in team inboxes; DMARC reports aren&apos;t counted as received email.
</p>
</div>
</main>
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/app/api/health/inbound/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { checkInboundHealth } from "~/server/service/inbound-health-service";
import { isInboundEnabled } from "~/server/service/inbound-storage";
import { NO_STORE, isAuthorized } from "../ses/shared";

export const dynamic = "force-dynamic";

export async function GET(request: Request) {
if (!isInboundEnabled()) {
return Response.json({ error: "Receiving isn't set up on this instance" }, { status: 404, headers: NO_STORE });
}

const health = await checkInboundHealth();
const body = isAuthorized(request) ? health : { status: health.status, checkedAt: health.checkedAt };
return Response.json(body, { status: health.status === "down" ? 503 : 200, headers: NO_STORE });
}
56 changes: 13 additions & 43 deletions apps/web/src/components/marketing/DevSection.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
"use client";

import React from "react";
import { useEffect, useState } from "react";
import Link from "next/link";
import { highlightCode, type HighlightLang } from "~/lib/highlighter";
import { useTheme } from "@bytesend/ui";
import { Button } from "@bytesend/ui/src/button";
import { LangToggle } from "~/components/marketing/CodeLangToggle";
import { CheckIcon } from "~/components/marketing/HomeIcons";

export function DevSection() {
const { resolvedTheme } = useTheme();

export async function DevSection() {
const APP_URL = "/login";
const containerId = "dev-lang-snippets";

Expand Down Expand Up @@ -143,6 +137,15 @@ puts res.body`;
{ key: "rb", label: "Ruby", kind: "rb", shikiLang: "ruby", code: RUBY_SNIPPET, file: "send_email.rb" },
];

const highlighted = await Promise.all(
languages.map((lang) =>
highlightCode(lang.code, {
lang: lang.shikiLang,
themes: { dark: "catppuccin-mocha", light: "catppuccin-latte" },
}).catch(() => ""),
),
);

return (
<section id="developers" className="scroll-mt-16 border-t border-border bg-muted/30 py-20 sm:py-24">
<div className="mx-auto max-w-6xl px-4 sm:px-6">
Expand Down Expand Up @@ -212,7 +215,7 @@ puts res.body`;
<div className="px-5 pt-3 text-[11px] text-muted-foreground font-mono bg-background/95 border-b border-border/70">
{lang.file}
</div>
<HighlightedSnippet code={lang.code} lang={lang.shikiLang} theme={resolvedTheme} />
<CodeSnippet code={lang.code} html={highlighted[idx] ?? ""} />
</div>
))}
</div>
Expand All @@ -222,41 +225,8 @@ puts res.body`;
);
}

function HighlightedSnippet({ code, lang, theme }: { code: string; lang: HighlightLang; theme?: string }) {
const [html, setHtml] = useState("");
const [loading, setLoading] = useState(true);
const shikiTheme = theme === "light" ? "catppuccin-latte" : "catppuccin-mocha";

useEffect(() => {
let mounted = true;

async function highlight() {
try {
const highlighted = await highlightCode(code, { lang, theme: shikiTheme });

if (mounted) {
setHtml(highlighted);
}
} catch {
if (mounted) {
setHtml("");
}
} finally {
if (mounted) {
setLoading(false);
}
}
}

setLoading(true);
void highlight();

return () => {
mounted = false;
};
}, [code, lang, shikiTheme]);

if (loading || !html) {
function CodeSnippet({ code, html }: { code: string; html: string }) {
if (!html) {
return (
<pre className="overflow-x-auto bg-background px-5 py-5 text-[13px] leading-[1.7] text-foreground/85">
<code>{code}</code>
Expand Down
10 changes: 10 additions & 0 deletions apps/web/src/server/aws/ses-receiving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export function inboundMxHost(region: string = env.INBOUND_REGION) {
return `inbound-smtp.${region}.amazonaws.com`;
}

export async function getReceivingRuleState(region: string = env.INBOUND_REGION) {
const active = await getClassicClient(region).send(new DescribeActiveReceiptRuleSetCommand({}));
const rule = active.Rules?.find((r) => r.Name === INBOUND_RULE);
return {
ruleSetActive: active.Metadata?.Name === INBOUND_RULE_SET,
ruleEnabled: Boolean(rule?.Enabled),
notifiesTopic: Boolean(rule?.Actions?.some((action) => action.S3Action?.TopicArn)),
};
}

export async function ensureReceivingRules({
region = env.INBOUND_REGION,
bucket = env.INBOUND_S3_BUCKET,
Expand Down
21 changes: 20 additions & 1 deletion apps/web/src/server/jobs/inbound-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DEFAULT_QUEUE_OPTIONS, INBOUND_CLEANUP_QUEUE, INBOUND_QUEUE } from "../
import { logger } from "../logger/log";
import { deleteExpiredInbound, processInbound, type SesInboundNotification } from "../service/inbound-service";
import { deleteExpiredDmarcReports } from "../service/dmarc-service";
import { INBOUND_CANARY_INTERVAL_MS, inboundCanaryAddress, sendInboundCanary } from "../service/inbound-canary";

let inboundQueue: Queue<SesInboundNotification> | null = null;
let initialized = false;
Expand All @@ -26,6 +27,11 @@ export async function enqueueInbound(notification: SesInboundNotification) {
});
}

export async function getInboundQueueCounts() {
const counts = await getInboundQueue().getJobCounts("waiting", "active", "delayed", "failed");
return { waiting: counts.waiting ?? 0, active: counts.active ?? 0, delayed: counts.delayed ?? 0, failed: counts.failed ?? 0 };
}

export async function initInboundJobs() {
if (initialized) return;
const connection = getRedis();
Expand All @@ -43,7 +49,11 @@ export async function initInboundJobs() {
const cleanupQueue = new Queue(INBOUND_CLEANUP_QUEUE, { connection, prefix: BULL_PREFIX, skipVersionCheck: true });
const cleanupWorker = new Worker(
INBOUND_CLEANUP_QUEUE,
async () => {
async (job) => {
if (job.name === "canary") {
await sendInboundCanary();
return;
}
const deleted = await deleteExpiredInbound();
const reports = await deleteExpiredDmarcReports();
logger.info({ deleted, reports }, "[InboundJob]: Removed expired received mail and DMARC reports");
Expand All @@ -52,6 +62,15 @@ export async function initInboundJobs() {
);
cleanupWorker.on("failed", (job, err) => logger.error({ err, jobId: job?.id }, "[InboundJob]: Cleanup failed"));
await cleanupQueue.upsertJobScheduler("inbound-cleanup-daily", { pattern: "40 3 * * *", tz: "UTC" }, { opts: { ...DEFAULT_QUEUE_OPTIONS } });
if (inboundCanaryAddress()) {
await cleanupQueue.upsertJobScheduler(
"inbound-canary",
{ every: INBOUND_CANARY_INTERVAL_MS },
{ name: "canary", opts: { ...DEFAULT_QUEUE_OPTIONS } },
);
} else {
await cleanupQueue.removeJobScheduler("inbound-canary");
}

initialized = true;
}
48 changes: 48 additions & 0 deletions apps/web/src/server/service/inbound-canary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { env } from "~/env";
import { logger } from "../logger/log";
import { getRedis, redisKey } from "../redis";

export const INBOUND_CANARY_INTERVAL_MS = 10 * 60 * 1000;
export const INBOUND_CANARY_SLUG = "status-canary";
const FIRST_SENT_KEY = "inbound:canary:first-sent";
const LAST_SENT_KEY = "inbound:canary:last-sent";
const LAST_SEEN_KEY = "inbound:canary:last-seen";

export function inboundCanaryAddress() {
return env.INBOUND_HOSTED_DOMAIN ? `${INBOUND_CANARY_SLUG}@${env.INBOUND_HOSTED_DOMAIN.toLowerCase()}` : null;
}

export function isInboundCanary(address: string) {
const canary = inboundCanaryAddress();
return canary !== null && address.trim().toLowerCase() === canary;
}

export async function recordInboundCanary() {
await getRedis().set(redisKey(LAST_SEEN_KEY), String(Date.now()));
}

export async function sendInboundCanary() {
const address = inboundCanaryAddress();
if (!address) return;
const { sendMail } = await import("../mailer");
const sentAt = new Date().toISOString();
await sendMail(
address,
`ByteSend receiving check ${sentAt}`,
`Automated receiving check sent at ${sentAt}.`,
`<p>Automated receiving check sent at ${sentAt}.</p>`,
);
const now = String(Date.now());
await getRedis().set(redisKey(FIRST_SENT_KEY), now, "NX");
await getRedis().set(redisKey(LAST_SENT_KEY), now);
logger.info({ address }, "[InboundCanary]: Sent");
}

export async function getInboundCanaryTimes() {
const [first, sent, seen] = await getRedis().mget(redisKey(FIRST_SENT_KEY), redisKey(LAST_SENT_KEY), redisKey(LAST_SEEN_KEY));
return {
firstSentAt: first ? Number(first) : null,
lastSentAt: sent ? Number(sent) : null,
lastSeenAt: seen ? Number(seen) : null,
};
}
Loading
Loading