expiring-email-routing is a Cloudflare Email Worker that redirects or drops emails based on an expiration date embedded in the recipient address.
The email worker parses the recipient email address for a date in YYYY-MM-DD format and only forwards the email if the date has not passed:
mailbox+2029-01-01@example.dev → mailbox@example.dev
catchall.2029-01-01@example.dev → steve.jobs@icloud.com
expired.2024-12-31@example.dev → 🗑️
-
Enable Cloudflare Email Routing:
Dashboard → Account → Domain → Email RoutingUse a new or unused domain name with Email Routing. Cloudflare offers registrations priced at cost.
-
Add verified destination addresses:
Domain → Email Routing → Destination addressesAt least one destination address is required. Email workers can only route to email address that have been approved as destination addresses. This restriction also applies to routing between email address with the same domain.
-
Cloudflare Dashboard:
Dashboard … Workers → Create an application → Clone a repository:http://github.com/andesco/expiring-email-routing -
Wrangler CLI:
git clone https://github.com/andesco/expiring-email-routing cd expiring-email-routing # edit wrangler.toml wrangler deploy
If your catch-all address is enabled, you can effectively use expiring-email-routing with all your custom addresses:
-
Enable catch-all address:
Domain → Email Routing → Routing Rules
Active -
Send catch-all address to Worker:
Domain → Email Routing → Routing Rules → Edit catch-all address
Edit
Action: Send to a Worker
Destination: expiring-email-routing
Save -
Use the catach-all address:
catchall.{YYYY-MM-DD}@example.dev→FORWARD_TOcustom-address.{YYYY-MM-DD}@example.dev→custom-address@example.dev
If your catch-all address is disabled, you can selectively use expiring-email-routing with a custom addresses:
-
Enable subaddressing:
Domain → Email Routing → Settings -
Send custom addresses to Worker:
Domain → Email Routing → Routing Rules
Create address or Edit
Action: Send to a Worker
Destination: expiring-email-routing
Save -
Use your custom addresses with subaddressing:
mailbox+{date}@example.dev→FORWARD_TOmailbox+{CUSTOM_TAG}@example.dev→CUSTOM_TAGmailbox+{date}+{CUSTOM_TAG}@example.dev→CUSTOM_TAG
Note
Subaddressing is also known as sub-addressing, plus addressing, and tagged addressing.
Important
Email workers can only route to email address that have been approved as destination addresses. This restriction also applies to routing between email address with the same domain.
- optional boolean
- drop emails with no date in address:
true - route emails with or without a date in address:
false· default
- optional
- If the email address contains a date in the past, the worker drops the email.
- Set your preferred timezone to determine the end of your day relative to UTC. Examples:
-7Pacific Time
-4Eastern Time · default
0UTC
+8Singapore
-964 day buffer
- optional email address
- If subaddresses is enabled and a
{CUSTOM_TAG}is included in the address, the email worker routes to{CUSTOM_TAG}first.
- optional email address
- If
FORWARD_TOis set, the email worker routes toFORWARD_TO: - If
FORWARD_TOis not set, the worker strips the date and attempts to route to a custom address:
custom-address.YYYY-MM-DD@example.com→custom-address@example.com
npm run deploy # wrangler deploy --config wrangler.local.toml
npm run dev # wrangler dev --config wrangler.local.toml