Skip to main content

Cloudflare Worker Configuration

The Cloudflare Worker requires specific configuration to function correctly. This involves setting environment variables and secrets.

Environment Variables

These variables are used for general configuration of the worker.

  • EMAIL_OPTIONS: A JSON string containing configuration options.

    • default_email_address: Your real email address where forwarded emails will be sent.
    • ignore_email_checks: An array of email addresses that will bypass HMAC validation (e.g., trusted senders).

    Example EMAIL_OPTIONS:

    {
    "default_email_address": "your-real-email@gmail.com",
    "ignore_email_checks": ["trusted-receiver@example.com"]
    }
  • DOMAIN: Your email domain (e.g., "example.com").

Secrets

Secrets are sensitive pieces of information that should not be committed to your codebase.

  • EMAIL_SECRET_MAPPING: A JSON string mapping secret keys to destination email addresses. These keys are generated by the browser extension and are used to validate incoming emails.

    Example EMAIL_SECRET_MAPPING:

    {
    "secret1": "user1@gmail.com",
    "secret2": "user2@gmail.com"
    }

    Important: The secret keys (secret1, secret2, etc.) in this mapping are generated by the browser extension. You will add these to your worker's secrets after setting up the browser extension.

wrangler.toml Configuration

When deploying with Wrangler CLI, you'll use a wrangler.toml file to define your worker's settings. A template is usually provided in the worker's repository.

name = "email-gateway-prod"
main = "dist/worker.js"
compatibility_date = "2025-07-08" # Use a recent date

[vars]
EMAIL_OPTIONS = '{"default_email_address":"your-real-email@gmail.com","ignore_email_checks":["trusted-receiver@example.com"]}'

[[email]]
name = "email-gateway-prod"
destination_confirmed = true
  • name: A unique name for your worker.
  • main: Path to your worker's compiled JavaScript file.
  • compatibility_date: Set this to a recent date to ensure compatibility with the latest Cloudflare Worker features.
  • [vars]: This section holds your environment variables.
  • [[email]]: This section configures email routing for your worker.
    • name: Should match the worker's name.
    • destination_confirmed: Set to true after you've confirmed your destination email address in Cloudflare.