This guide provides step-by-step instructions to deploy the Open-Temp-Mail application to Cloudflare Workers. It covers everything from setting up your environment to rigorous verification.
Before starting, ensure you have the following installed:
- Node.js & npm: Download and install from Node.js official website. (Version 18 or higher recommended).
- Git: Download and install from Git official website.
- Cloudflare Account: Sign up at Cloudflare if you don't have one.
We provide a script to automate the entire setup process.
- Install & Login:
npm install -g wrangler wrangler login
- Run Setup:
Follow the interactive prompts to set up your database, secrets, and deploy.
npm run deploy:setup
If you prefer to set up everything manually, follow these steps.
The Wrangler CLI is the command-line tool for building and managing Cloudflare Workers.
- Open your terminal (Command Prompt, PowerShell, or macOS Terminal).
- Install Wrangler globally:
npm install -g wrangler
- Verify the installation:
wrangler --version
Connect your local environment to your Cloudflare account.
- Run the login command:
wrangler login
- A browser window will open asking you to authorize Wrangler.
- Click "Allow".
- Close the browser tab once you see the success message.
- In your terminal, you should see:
Successfully logged in.
Navigate to the project directory and install dependencies.
-
Open your terminal in the project folder:
cd "path/to/open-temp-mail"
(Navigate to where you cloned the repository)
-
Install project dependencies:
npm install
You need two main resources: a D1 Database (for storing user/mailbox data) and an R2 Bucket (for storing full email contents).
- Run the creation command:
wrangler d1 create maill_free_db
- Copy the output! You will see something like this:
[[d1_databases]] binding = "TEMP_MAIL_DB" # IMPORTANT: Must be TEMP_MAIL_DB database_name = "maill_free_db" database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- Open
wrangler.tomlin your text editor. - Replace the
[[d1_databases]]section with the output from Step 2.- CRITICAL: Ensure
binding = "TEMP_MAIL_DB". If the output says "DB", change it to "TEMP_MAIL_DB".
- CRITICAL: Ensure
- Run the creation command:
wrangler r2 bucket create mail-eml
- Open
wrangler.tomland verify the[[r2_buckets]]section:[[r2_buckets]] binding = "MAIL_EML" bucket_name = "mail-eml"
Open wrangler.toml and configure the [vars] section.
- MAIL_DOMAIN: Your email domain(s), separated by commas.
- Example:
"example.com, temp.example.com"
- Example:
- ADMIN_NAME: The username for the admin dashboard.
- Default:
"admin"
- Default:
Do NOT put passwords in wrangler.toml. Set them securely using wrangler secret put.
Run the following commands in your terminal:
-
Admin Password:
wrangler secret put ADMIN_PASSWORD
Enter your desired strong password when prompted.
-
JWT Token Secret (for session security):
wrangler secret put JWT_TOKEN # Enter a long, random string (e.g., generated via `openssl rand -hex 32`) -
Resend API Key (Optional, for sending emails):
wrangler secret put RESEND_API_KEY # Enter your key from https://resend.com
Now, build the frontend and deploy the full stack to Cloudflare.
-
Build the Frontend: This compiles your React code into static assets in the
dist/folder.npm run build
-
Deploy to Cloudflare Workers: This uploads your backend code and the static assets.
wrangler deploy
-
Success! The terminal will output your Worker's URL, e.g.,
https://open-temp-mail.your-subdomain.workers.dev.
To receive emails, you must configure Cloudflare Email Routing.
- Go to the Cloudflare Dashboard.
- Select your domain.
- Navigate to Email > Email Routing.
- Click "Get Started" if not already enabled.
- Go to the Routes tab.
- Click Create Custom Address.
- Custom Address: Enter
*(Catch-all) to receive emails for any address (e.g.,anything@yourdomain.com). - Action:
Send to a Worker. - Destination: Select your newly deployed Worker (
open-temp-mail).
- Custom Address: Enter
- Click Save.
- Open your Worker URL in a browser.
- You should see the Open-Temp-Mail login page.
- Login with
adminand the password you set in Step 5. - Try creating a random mailbox to test database connectivity.
- Try sending an email to that mailbox (from an external account like Gmail) to test Email Routing.
- Frontend loads blank: Open your browser's Developer Tools (F12) -> Console. Check for errors.
- Database errors: Ensure you ran the
d1 executecommand (Step 4.2). - "Uncaught (in promise)": Check your
wrangler secret listto ensure all secrets are set. - Email not received: Verify your domain's MX records in Cloudflare DNS settings match what Email Routing requires.
You can run the application locally in two modes: Local Mode (using a local temporary database) or Remote Mode (connecting to your live Cloudflare D1 database).
Use this for safe development without affecting production data.
-
Start Frontend:
npm run dev
(Runs on
http://localhost:5173) -
Start Backend (in a new terminal):
npm run dev:backend
(Runs on
http://localhost:8787using a local SQLite file)
Use this to debug with your actual production database.
-
Start Frontend:
npm run dev
-
Start Backend (in a new terminal):
npm run dev:backend:remote
(Runs on
http://localhost:8787but connects to your generic Cloudflare D1 DB)