CLI deploy
You need Node.js 22+ and Git.
Clone and build
git clone https://github.com/PastKing/xi-mail.git
cd xi-mail/mail-worker
npm ci
npx wrangler login
cd ../mail-view
npm install
npm run build
cd ../mail-worker
npx wrangler deployThe first deploy creates D1 (db) and KV (kv) and prints a workers.dev URL.
Secrets
Add Text admin in Cloudflare Settings, or set it in a private [vars] block. Put secrets with:
npx wrangler secret put jwt_secret
npx wrangler secret put init_secretThe two secrets must differ and be at least 32 characters. Then open:
https://your-site/api/init/your-init_secretRegister with the admin email. Then follow Get started to receive mail.
Existing databases
When you change accounts, rename the Worker, or move from the dashboard to local deploys, put the original IDs in gitignored wrangler.local.toml:
[[d1_databases]]
binding = "db"
database_id = "existing-d1-id"
[[kv_namespaces]]
binding = "kv"
id = "existing-kv-id"Then use npm run deploy:local. Do not point at a new empty database.
Sub-worker
The sub-worker has no login page. It only receives mail and exposes a query API.
cd mail-worker-sub
npm install
npx wrangler login
npx wrangler deploy
npx wrangler secret put api_token
curl -H "x-api-token: <api_token>" https://xi-mail-sub.<your-subdomain>.workers.dev/initAdd Text domain (comma-separated suffixes) on the sub-worker, point Catch-all to xi-mail-sub, then add the URL and token under Settings → Sub-workers on the main site.
To keep a separate Cloudflare login, use cf.ps1 in that directory. Full API: Sub-worker.