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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

---

## [Unreleased]
## [0.9.3] - 2026-10-21

### Added
- **Receive on the domain itself**: as well as a subdomain like `reply.acme.com`, a domain can now receive at `anything@acme.com`. Because that sends all of the domain's mail to ByteSend, setup shows where its mail goes today (Google Workspace, Microsoft 365 and so on) and asks you to confirm first

### Changed
- **Homepage**: the full pricing section and comparison table are replaced by a short pricing summary linking to `/pricing`, and an Explore section linking to receiving, the SMTP relay, the free tools, open source, security and the comparison
Expand Down
12 changes: 12 additions & 0 deletions apps/docs/guides/inbound-email.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ You receive on a **subdomain** of a domain you already send from, such as `reply
</Step>
</Steps>

### Receiving on the domain itself

You can also receive at the domain itself, like `hey@acme.com`. Choose **The domain itself** instead of a subdomain, then point the domain's MX record at the value shown:

| Type | Name | Value | Priority |
| --- | --- | --- | --- |
| MX | `@` | `inbound-smtp.us-east-1.amazonaws.com` | 10 |

<Warning>
A domain has one set of MX records, so this sends **all** mail for the domain to ByteSend. If you use Google Workspace, Microsoft 365 or another mailbox on the domain, those mailboxes stop getting new mail. ByteSend shows where the domain's mail goes today and asks you to confirm before switching. To keep your mailboxes, use a subdomain instead, or add [forwarding rules](#forwarding) for the addresses that should still reach a person.
</Warning>

## The `email.received` webhook

Add a webhook and choose the **email.received** event (under *Inbound events*). Each message is posted as JSON:
Expand Down
90 changes: 73 additions & 17 deletions apps/web/src/app/(dashboard)/inbox/receiving-addresses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ type ReceivingDomain = inferRouterOutputs<AppRouter>["inbound"]["domains"][numbe

function DomainReceiving({ domain, canEdit }: { domain: ReceivingDomain; canEdit: boolean }) {
const [subdomain, setSubdomain] = useState("reply");
const [mode, setMode] = useState<"subdomain" | "root">("subdomain");
const [confirmed, setConfirmed] = useState(false);
const mailHosts = api.inbound.mailHosts.useQuery({ domainId: domain.id }, { enabled: mode === "root" && !domain.inboundEnabled });
const otherMailbox = mailHosts.data && mailHosts.data.hosts.length > 0 && !mailHosts.data.alreadyByteSend;
const utils = api.useUtils();
const refresh = () => utils.inbound.domains.invalidate();

const enable = api.inbound.enableDomain.useMutation({ onSuccess: refresh, onError: (e) => toast.error(e.message) });
const check = api.inbound.checkDomain.useMutation({
onSuccess: async (result) => {
await refresh();
if (result.domain.inboundStatus === "SUCCESS") toast.success(`${result.domain.inboundSubdomain}.${domain.name} is ready to receive mail`);
if (result.domain.inboundStatus === "SUCCESS") toast.success(`${domain.address ?? domain.name} is ready to receive mail`);
else toast.message(result.mx ? "MX found. Still waiting for the DKIM record." : "We can't see the MX record yet. DNS can take a while to update.");
},
onError: (e) => toast.error(e.message),
Expand All @@ -40,29 +44,79 @@ function DomainReceiving({ domain, canEdit }: { domain: ReceivingDomain; canEdit
<div className="min-w-0">
<p className="text-[13px] font-medium text-foreground">{domain.name}</p>
<p className="text-xs text-muted-foreground">
{domain.status === "SUCCESS" ? "Not receiving. Pick a subdomain to receive on." : "Verify this domain for sending first."}
{domain.status === "SUCCESS" ? "Not receiving. Receive on a subdomain, or on the domain itself." : "Verify this domain for sending first."}
</p>
</div>
{canEdit && domain.status === "SUCCESS" ? (
<form
className="flex items-center gap-2"
className="flex flex-col gap-2 sm:items-end"
onSubmit={(e) => {
e.preventDefault();
enable.mutate({ domainId: domain.id, subdomain });
enable.mutate({ domainId: domain.id, subdomain: mode === "root" ? "@" : subdomain, confirmRoot: mode === "root" });
}}
>
<div className="flex h-8 items-center rounded-md border border-input bg-background text-[13px] shadow-xs focus-within:ring-2 focus-within:ring-ring/20">
<Input
value={subdomain}
onChange={(e) => setSubdomain(e.target.value.toLowerCase())}
className="h-full w-24 border-0 bg-transparent px-2 text-[13px] shadow-none focus-visible:ring-0"
aria-label="Subdomain"
/>
<span className="pr-2 text-muted-foreground">.{domain.name}</span>
<div role="radiogroup" aria-label="Where to receive" className="inline-flex rounded-md border border-border bg-muted/50 p-0.5 text-xs">
{(
[
["subdomain", "A subdomain"],
["root", "The domain itself"],
] as const
).map(([value, label]) => (
<button
key={value}
type="button"
role="radio"
aria-checked={mode === value}
onClick={() => {
setMode(value);
setConfirmed(false);
}}
className={`rounded-[5px] px-2.5 py-1 font-medium transition-colors ${
mode === value ? "bg-background text-foreground shadow-xs" : "text-muted-foreground hover:text-foreground"
}`}
>
{label}
</button>
))}
</div>
<Button size="sm" type="submit" isLoading={enable.isPending}>
Set up
</Button>
<div className="flex items-center gap-2">
{mode === "subdomain" ? (
<div className="flex h-8 items-center rounded-md border border-input bg-background text-[13px] shadow-xs focus-within:ring-2 focus-within:ring-ring/20">
<Input
value={subdomain}
onChange={(e) => setSubdomain(e.target.value.toLowerCase())}
className="h-full w-24 border-0 bg-transparent px-2 text-[13px] shadow-none focus-visible:ring-0"
aria-label="Subdomain"
/>
<span className="pr-2 text-muted-foreground">.{domain.name}</span>
</div>
) : (
<span className="font-mono text-[13px] text-foreground">anything@{domain.name}</span>
)}
<Button size="sm" type="submit" isLoading={enable.isPending} disabled={mode === "root" && (mailHosts.isLoading || (otherMailbox && !confirmed))}>
Set up
</Button>
</div>
{mode === "root" && mailHosts.data ? (
otherMailbox ? (
<div className="max-w-md rounded-md border border-warning/30 bg-warning/[0.07] p-3 text-xs text-foreground sm:text-left">
<p>
Mail for <span className="font-medium">{domain.name}</span> currently goes to{" "}
<span className="font-medium">{mailHosts.data.provider ?? mailHosts.data.hosts[0]!.host}</span>. Receiving here sends{" "}
<span className="font-medium">all</span> of it to ByteSend instead, so those mailboxes stop getting new mail. Use a subdomain if
you want to keep them, or forwarding rules to pass addresses on.
</p>
<label className="mt-2 flex items-start gap-2 text-muted-foreground">
<input type="checkbox" className="mt-0.5" checked={confirmed} onChange={(e) => setConfirmed(e.target.checked)} />
I understand all mail for {domain.name} will come to ByteSend
</label>
</div>
) : (
<p className="max-w-md text-xs text-muted-foreground sm:text-right">
{mailHosts.data.alreadyByteSend ? `${domain.name} already points at ByteSend.` : `${domain.name} doesn't receive mail anywhere else today, so nothing else is affected.`}
</p>
)
) : null}
</form>
) : null}
</div>
Expand Down Expand Up @@ -111,7 +165,9 @@ function DomainReceiving({ domain, canEdit }: { domain: ReceivingDomain; canEdit
</div>
))}
<p className="text-xs text-muted-foreground">
Only this subdomain&apos;s mail comes to ByteSend. Your normal mailboxes on {domain.name} aren&apos;t affected.
{domain.inboundSubdomain === "@"
? `All mail for ${domain.name} will come to ByteSend once this MX record is in place, replacing any existing MX records. Add forwarding rules for addresses that should still reach a mailbox.`
: `Only this subdomain's mail comes to ByteSend. Your normal mailboxes on ${domain.name} aren't affected.`}
</p>
</div>
) : null}
Expand All @@ -131,7 +187,7 @@ export function ReceivingAddresses({ hostedAddress, region }: { hostedAddress: s
</Panel>
) : null}

<Panel flush title="Your domains" description={`Receive on a subdomain of a domain you send from. Mail is received in ${region ?? "us-east-1"}.`}>
<Panel flush title="Your domains" description={`Receive on a subdomain like reply.yourdomain.com, or on the domain itself. Mail is received in ${region ?? "us-east-1"}.`}>
{domains.isLoading ? (
<ListSkeleton rows={2} />
) : !domains.data?.length ? (
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/server/api/routers/dmarc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "~/server/service/dmarc-service";
import { ensureInboundSlug } from "~/server/service/inbound-service";
import { isInboundEnabled } from "~/server/service/inbound-storage";
import { receivingFqdn } from "~/server/service/inbound-domain-service";

const PAGE_SIZE = 25;
const DAYS = z.union([z.literal(7), z.literal(30), z.literal(90)]);
Expand All @@ -25,7 +26,7 @@ async function reportAddresses(teamId: number) {
return {
hosted: hostedDmarcAddress(slug),
byOrgDomain: new Map(
receiving.map((d) => [tldts.getDomain(d.name) ?? d.name, `${DMARC_TAG}@${d.inboundSubdomain}.${d.name}`] as const),
receiving.map((d) => [tldts.getDomain(d.name) ?? d.name, `${DMARC_TAG}@${receivingFqdn(d)}`] as const),
),
};
}
Expand Down
9 changes: 7 additions & 2 deletions apps/web/src/server/api/routers/inbound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "~/server/service/inbound-service";
import {
checkReceiving,
currentMailHosts,
disableReceiving,
enableReceiving,
receivingFqdn,
Expand Down Expand Up @@ -119,16 +120,20 @@ export const inboundRouter = createTRPCRouter({
return { success: true };
}),

mailHosts: teamProcedure
.input(z.object({ domainId: z.number().int() }))
.query(({ ctx, input }) => currentMailHosts(ctx.team.id, input.domainId)),

domains: teamProcedure.query(async ({ ctx }) => {
const domains = await ctx.db.domain.findMany({ where: { teamId: ctx.team.id }, select: RECEIVING_DOMAIN_SELECT, orderBy: { name: "asc" } });
return domains.map((domain) => ({ ...domain, address: receivingFqdn(domain), records: receivingRecords(domain) }));
}),

enableDomain: teamAdminProcedure
.input(z.object({ domainId: z.number().int(), subdomain: z.string().min(1).max(63) }))
.input(z.object({ domainId: z.number().int(), subdomain: z.string().max(63), confirmRoot: z.boolean().default(false) }))
.mutation(async ({ ctx, input }) => {
assertEnabled();
const domain = await enableReceiving(ctx.team.id, input.domainId, input.subdomain);
const domain = await enableReceiving(ctx.team.id, input.domainId, input.subdomain, input.confirmRoot);
return { ...domain, address: receivingFqdn(domain), records: receivingRecords(domain) };
}),

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/server/service/cloudflare-dns-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as tldts from "tldts";
import type { Domain } from "@prisma/client";
import { logger } from "../logger/log";
import { buildDnsRecords } from "./domain-service";
import { receivingRecords } from "./inbound-domain-service";
import { ROOT_RECEIVING, receivingRecords } from "./inbound-domain-service";

const API = "https://api.cloudflare.com/client/v4";
const TXT_CHUNK = 255;
Expand Down Expand Up @@ -61,7 +61,7 @@ export function desiredRecords(domain: Domain): DesiredRecord[] {
const receiving = domain.inboundEnabled
? receivingRecords(domain).map((record): DesiredRecord => ({
type: record.type,
name: `${record.name}.${domain.name}`,
name: record.name === ROOT_RECEIVING ? domain.name : `${record.name}.${domain.name}`,
content: record.value,
priority: record.priority,
kind: record.type === "MX" ? "mx" : "dkim",
Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/server/service/domain-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import util from "util";
import * as tldts from "tldts";
import * as ses from "~/server/aws/ses";
import { deleteReceivingIdentity } from "../aws/ses-receiving";
import { receivesThroughKeptIdentity } from "./inbound-domain-service";
import { receivesThroughKeptIdentity, receivingFqdn } from "./inbound-domain-service";
import { db } from "~/server/db";
import { env } from "~/env";
import { renderDomainVerificationStatusEmail } from "~/server/email-templates";
Expand Down Expand Up @@ -957,9 +957,10 @@ export async function deleteDomain(id: number) {
}
}

if (domain.inboundEnabled && domain.inboundSubdomain && domain.inboundDkimSelector) {
const receivingHost = receivingFqdn(domain);
if (domain.inboundEnabled && receivingHost && domain.inboundDkimSelector) {
try {
await deleteReceivingIdentity(`${domain.inboundSubdomain}.${domain.name}`);
await deleteReceivingIdentity(receivingHost);
} catch (error) {
logger.error({ err: error, domainId: id }, "[DomainService]: Failed to delete receiving identity");
}
Expand Down
56 changes: 48 additions & 8 deletions apps/web/src/server/service/inbound-domain-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,56 @@ export function receivesThroughKeptIdentity(domain: Pick<Domain, "region" | "inb
return domain.inboundEnabled && !domain.inboundDkimSelector && domain.region !== env.INBOUND_REGION;
}

export const ROOT_RECEIVING = "@";

export function isRootReceiving(domain: Pick<Domain, "inboundSubdomain">) {
return domain.inboundSubdomain === ROOT_RECEIVING;
}

export function receivingFqdn(domain: Pick<Domain, "name" | "inboundSubdomain">) {
return domain.inboundSubdomain ? `${domain.inboundSubdomain}.${domain.name}` : null;
if (!domain.inboundSubdomain) return null;
return isRootReceiving(domain) ? domain.name : `${domain.inboundSubdomain}.${domain.name}`;
}

export function receivingRecords(domain: ReceivingDomain) {
if (!domain.inboundSubdomain) return [];
const records: Array<{ type: "MX" | "TXT"; name: string; value: string; priority?: number }> = [
{ type: "MX", name: domain.inboundSubdomain, value: inboundMxHost(), priority: 10 },
{ type: "MX", name: isRootReceiving(domain) ? ROOT_RECEIVING : domain.inboundSubdomain, value: inboundMxHost(), priority: 10 },
];
if (domain.inboundDkimSelector && domain.inboundPublicKey) {
records.push({
type: "TXT",
name: `${domain.inboundDkimSelector}._domainkey.${domain.inboundSubdomain}`,
name: isRootReceiving(domain)
? `${domain.inboundDkimSelector}._domainkey`
: `${domain.inboundDkimSelector}._domainkey.${domain.inboundSubdomain}`,
value: `p=${domain.inboundPublicKey}`,
});
}
return records;
}

export async function enableReceiving(teamId: number, domainId: number, rawSubdomain: string) {
const subdomain = rawSubdomain.trim().toLowerCase();
if (!LABEL.test(subdomain)) {
export async function enableReceiving(teamId: number, domainId: number, rawSubdomain: string, confirmRoot = false) {
const requested = rawSubdomain.trim().toLowerCase();
const root = requested === "" || requested === ROOT_RECEIVING;
const subdomain = root ? ROOT_RECEIVING : requested;
if (!root && !LABEL.test(subdomain)) {
throw new TRPCError({ code: "BAD_REQUEST", message: "Use a single subdomain like \"reply\" or \"inbound\": letters, numbers and dashes." });
}
if (root && !confirmRoot) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Receiving on the domain itself sends all of its mail to ByteSend. Confirm that before turning it on.",
});
}
const domain = await db.domain.findFirst({ where: { id: domainId, teamId }, select: RECEIVING_DOMAIN_SELECT });
if (!domain) throw new TRPCError({ code: "NOT_FOUND", message: "Domain not found" });
if (domain.status !== "SUCCESS") {
throw new TRPCError({ code: "BAD_REQUEST", message: "Verify the domain for sending first, then set up receiving." });
}

const fqdn = `${subdomain}.${domain.name}`;
const needsIdentity = domain.region !== env.INBOUND_REGION;
const fqdn = root ? domain.name : `${subdomain}.${domain.name}`;
const alreadyVerified = root && domain.region !== env.INBOUND_REGION && (await isIdentityVerified(fqdn).catch(() => false));
const needsIdentity = domain.region !== env.INBOUND_REGION && !alreadyVerified;
const identity = needsIdentity ? await createReceivingIdentity(fqdn, INBOUND_DKIM_SELECTOR) : null;

return db.domain.update({
Expand All @@ -80,6 +98,28 @@ export async function enableReceiving(teamId: number, domainId: number, rawSubdo
});
}

const MAIL_PROVIDERS: Array<[RegExp, string]> = [
[/(google|googlemail)\.com$/, "Google Workspace"],
[/mail\.protection\.outlook\.com$/, "Microsoft 365"],
[/zoho\.(com|eu|in)$/, "Zoho Mail"],
[/protonmail\.ch$/, "Proton Mail"],
[/messagingengine\.com$/, "Fastmail"],
[/icloud\.com$/, "iCloud Mail"],
[/mx\.cloudflare\.net$/, "Cloudflare Email Routing"],
[/amazonaws\.com$/, "Amazon SES"],
];

export async function currentMailHosts(teamId: number, domainId: number) {
const domain = await db.domain.findFirst({ where: { id: domainId, teamId }, select: { name: true } });
if (!domain) throw new TRPCError({ code: "NOT_FOUND", message: "Domain not found" });
const records = await dns.promises.resolveMx(domain.name).catch(() => []);
const hosts = records
.sort((a, b) => a.priority - b.priority)
.map((record) => ({ host: record.exchange.toLowerCase().replace(/\.$/, ""), priority: record.priority }));
const provider = hosts.map((h) => MAIL_PROVIDERS.find(([pattern]) => pattern.test(h.host))?.[1]).find(Boolean) ?? null;
return { domain: domain.name, hosts, provider, alreadyByteSend: hosts.some((h) => h.host === inboundMxHost()) };
}

async function mxPointsAtSes(fqdn: string) {
try {
const records = await dns.promises.resolveMx(fqdn);
Expand Down
Loading
Loading