1import * as Cloudflare from "alchemy/Cloudflare";
2
3/**
4 * Cloudflare zone the example operates on. The same zone is used for
5 * inbound (Email Routing) and outbound (`send_email` sender domain).
6 */
7export const ZONE = "alchemy-test-2.us";
8
9/**
10 * `from:` address the Worker is allowed to send mail as. Must live on a
11 * sender domain with Email Routing enabled — the `Cloudflare.email(...)`
12 * subscribe in `Api.ts` auto-creates the `EmailRouting` toggle for us.
13 */
14export const SENDER = process.env.CLOUDFLARE_EMAIL_FROM ?? `bot@${ZONE}`;
15
16/**
17 * Destination the Worker is pinned to send to. Cloudflare requires this
18 * address to be verified (recipient clicks a confirmation link) before
19 * `send_email` will deliver.
20 */
21export const DESTINATION =
22 process.env.CLOUDFLARE_EMAIL_TO ?? "michael@alchemy.run";
23
24/**
25 * Inbox address the Worker subscribes to. Mail addressed here is routed
26 * to the Worker's `email` handler via the `EmailRule` that the
27 * `Cloudflare.email({ zone, matchers }).subscribe(...)` call auto-creates.
28 */
29export const INBOX = process.env.CLOUDFLARE_EMAIL_INBOX ?? `inbox@${ZONE}`;
30
31/**
32 * Register the destination address on the account. Cloudflare emails a
33 * verification link the first time this address is added; until the
34 * recipient clicks it, `send_email` calls targeting it will fail.
35 */
36export const Destination = Cloudflare.Email.Address("Destination", {
37 email: DESTINATION,
38});
39
40/**
41 * `send_email` Worker binding restricted to the sender/destination pair
42 * above so the Worker can't be tricked into emailing arbitrary recipients.
43 */
44export const SendEmail = Cloudflare.Email.SendEmail("Email", {
45 allowedSenderAddresses: [SENDER],
46 destinationAddress: DESTINATION,
47});