# Deploying Mailflare to Vercel Run Mailflare on Vercel with a hosted database and file storage. [Cloudflare](deploy-cloudflare.md) and [Docker](deploy-docker.md) are recommended; Vercel needs more services and has [limits](#limits). ## Prerequisites | Service | Used for | Variables | | --- | --- | --- | | Vercel Hobby (non-commercial only) or Pro | App with 300 s functions, and [Vercel Queues](https://vercel.com/docs/queues) (beta) | | | PostgreSQL, MySQL or Turso | Records and rate limits | See [database](#database) | | Vercel Blob (**private**), AWS S3 or Backblaze B2 | Mail, attachments, Drive, backups | See [storage](#storage) | | A long random string | Protects cron routes | `CRON_SECRET` | | Public address | Links and webhooks | `APP_URL=https://mail.example.com`; default is the production domain | The app does not start until all of these are set. It lists what is missing. ## Deploy [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fhieunc229%2Fmailflare&env=CRON_SECRET&envDescription=See%20docs%2Fdeploy-vercel.md&envLink=https%3A%2F%2Fgithub.com%2Fhieunc229%2Fmailflare%2Fblob%2Fmain%2Fdocs%2Fdeploy-vercel.md) 1. Import the repository and set the variables. `vercel.json` sets the build command, queue consumer and daily cron jobs. 2. Add the [database](#database) and [storage](#storage), then redeploy. 3. With S3 or Backblaze, [allow browser uploads](#bucket-cors). 4. Turn off **Deployment Protection** for the production domain, so schedules and mail providers can reach it. 5. Open `/setup`, wait for [first setup](#first-setup), create the admin account and add your domain. 6. Start the [five-minute schedule](#five-minute-schedule). 7. Set up [receiving](#receiving-mail) and [sending](#sending-mail). Preview deployments need their own database, storage and `APP_URL`. ### Database Choose one: - **Connect in Vercel.** Add Turso from the Marketplace, press **Connect Project** and keep the default prefix. Mailflare reads `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN`. Databases that set `DATABASE_URL` (such as Neon) also work. - **Set it yourself.** `DATABASE_URL`, plus `DATABASE_AUTH_TOKEN` for Turso. `DATABASE_URL` wins over the Turso variables. > **Warning: turn database branching off.** With **Create database branch for deployment** on, each deployment gets its own copy, and saved data (including first setup) is missing in the next one. Uncheck it, at least for Production. To change it, disconnect the database, reconnect without it and redeploy. Data in old branches is not copied back. - Put the database in your functions' region (default `iad1`, Washington, D.C.), or change **Settings → Functions → Function Region** and redeploy. A distant database slows every page. - For PostgreSQL, use an HTTP driver (Neon) or a connection pooler. Otherwise each query opens a connection. See [databases](databases.md). ### Storage Choose one: | Option | Setup | | --- | --- | | Vercel Blob | **Storage** tab → create a store with **Private** access → connect with the default prefix. Mailflare reads `BLOB_STORE_ID` or `BLOB_READ_WRITE_TOKEN`. No CORS needed. A public store does not work. | | AWS S3 | `S3_BUCKET`, `S3_REGION`, `S3_ACCESS_KEY_ID`, `S3_SECRET_ACCESS_KEY`, then [CORS](#bucket-cors) | | Backblaze B2 | The four `B2_*` variables, then [CORS](#bucket-cors) | > **Warning: check the [Blob Hobby limits](https://vercel.com/docs/vercel-blob/usage-and-pricing).** 1 GB, 10,000 simple and 2,000 advanced operations a month. Each stored file is an advanced operation and each message stores several, so a few hundred messages can use the month. Over a limit, you lose Blob for 30 days and mail stops. An S3 or B2 bucket wins over Blob. Changing storage does not move existing files. ### Bucket CORS Uploads over 4 MB (attachments, Drive, imports, restores) go straight from the browser to storage. On S3, add: ```json [{ "AllowedOrigins": ["https://mail.example.com"], "AllowedMethods": ["PUT"], "AllowedHeaders": ["*"] }] ``` On Backblaze B2, add a CORS rule for `s3_put` with the same origin. ### First setup The first visit to `/setup` creates the tables. On Turso this runs over a hundred migrations and can take several minutes; the page shows **Checking installation**. If it seems stuck: 1. Leave the page open for five minutes. 2. Reload. Turso and PostgreSQL save each finished migration, so setup continues. Repeat if needed. 3. Move the functions near the [database](#database) and redeploy. 4. Still stuck? Search the Vercel logs for `/api/setup/prepare`. ### Five-minute schedule Reminders, imports, promotions sorting, auto-update and cleanup run every five minutes. Hobby allows only daily cron, so Mailflare schedules its own next run with a delayed queue message. Start it after deploying: ```bash curl https://mail.example.com/api/internal/cron/frequent -H "Authorization: Bearer $CRON_SECRET" ``` It runs on production only. If it stops, the next queued job or the daily cron (03:00 UTC) restarts it. It uses your queue quota. #### With QStash If you use QStash, create this schedule once instead: ```bash curl -X POST "https://qstash.upstash.io/v2/schedules/https://mail.example.com/api/internal/cron/frequent" \ -H "Authorization: Bearer $QSTASH_TOKEN" \ -H "Upstash-Schedule-Id: mailflare-frequent" \ -H "Upstash-Cron: */5 * * * *" \ -H "Upstash-Method: GET" \ -H "Upstash-Retries: 0" \ -H "Upstash-Forward-Authorization: Bearer $CRON_SECRET" ``` Outside the default region, use your `QSTASH_URL` as the host. Rerunning updates the schedule. It uses 288 messages a day. ## Optional services | Replace | With | Variables | | --- | --- | --- | | Vercel Queues | [Upstash QStash](https://upstash.com/docs/qstash), plus its [schedule](#with-qstash) | `QSTASH_TOKEN`, `QSTASH_CURRENT_SIGNING_KEY`, `QSTASH_NEXT_SIGNING_KEY`, and `QSTASH_URL` outside the default region | | Database rate limits | Upstash Redis | `UPSTASH_REDIS_REST_URL`, `UPSTASH_REDIS_REST_TOKEN` (or `KV_REST_API_*`) | ## Receiving mail Vercel cannot accept SMTP. Choose one: **Cloudflare Email Routing relay** 1. Deploy [`deploy/cloudflare-email-relay`](../deploy/cloudflare-email-relay/README.md). Set its `MAILFLARE_URL` to your deployment. 2. Give both the same `INBOUND_WEBHOOK_SECRET`. 3. Route the catch-all to the relay. 4. If Mailflare manages the zone with `CF_TOKEN`, set `CF_EMAIL_WORKER_NAME=mailflare-email-relay`. Redeploy an older relay: only the current one delivers messages over 4 MB. **Resend or Amazon SES:** choose per domain on the Domains page ([providers](providers.md)). ## Sending mail Use Resend or SES per domain, `SMTP_URL`, or `CF_ACCOUNT_ID` with `CF_TOKEN`. See [sending mail](deploy-docker.md#sending-mail). ## AI assistant - Set `AI_BASE_URL`, `AI_API_KEY` and `AI_MODEL`. - Set `MCP_ENCRYPTION_KEY` to encrypt saved MCP tokens ([token encryption](email-assistant-and-mcp.md#token-encryption)). ## Updating The admin update button pushes the new version to your repository, as on Cloudflare (`GITHUB_UPDATE_*`, see [updating](deployment.md#updating-mailflare)). Vercel deploys it. Then apply migrations in **Admin settings**, or turn on auto-update. ## Check a deployment ```bash CRON_SECRET= node scripts/vercel-smoke.mjs https://mail.example.com ``` Add `INBOUND_WEBHOOK_SECRET`, `SMOKE_TO` and `SMOKE_API_KEY` to also test delivery of a small and a large message. ## Limits | Area | Limit | | --- | --- | | Live updates | None; lists refresh every 30 seconds. Web Push works with `VAPID_*`. | | API requests | 4.5 MB. The web app works around it; REST, MCP and JMAP clients cannot. JMAP uploads: 4 MB. | | Attachments | Up to the 100 MB admin cap, uploaded in parts; files too large for the message go as download cards | | IMAP import | Not available; import `.eml`, `.mbox` or Google Takeout files | | Rate limits | Counted per instance if the database or Redis is unreachable | | Vercel Blob | No custom metadata (an unnamed JMAP upload loses its name); abandoned Drive uploads expire on Vercel's schedule | | Vercel Queues | Beta. Waiting jobs run on the deployment that queued them, so **keep recent deployments**. | | Long jobs | Each step of a large backup or import must finish within 300 s | ## Troubleshooting | Problem | Cause | Fix | | --- | --- | --- | | App refuses to start | Missing variables | Set what the error lists | | Data disappears after deploy | Database branching | Turn it off | | Setup stuck | Many migrations or distant database | See [first setup](#first-setup) | | Large uploads fail | Bucket CORS | See [bucket CORS](#bucket-cors) | | Reminders do not fire | Schedule not started | Start the [schedule](#five-minute-schedule) |