Skip to main content
Projects

EdgeMail

Open-source serverless email platform for Cloudflare Workers — powers ArgoBox's email system

March 8, 2026

EdgeMail

EdgeMail is a complete email backend running entirely on Cloudflare's edge infrastructure. It handles inbound email via CF Email Routing, outbound via Resend API, and provides full webmail features — threading, contacts, labels, folders, filters, autoresponder, templates, aliases, scheduled send, and full-text search.

Extracted from ArgoBox's production email module and packaged as a standalone open-source project.

Architecture

Inbound:  CF Email Routing → Worker → EmailReceiver → D1 (parse, filter, store)
Outbound: API request → EmailSender → Resend API → D1 (draft-then-promote)
Storage:  D1 (SQLite) for metadata/body, R2 for attachments
Search:   FTS5 full-text search with LIKE fallback
Auth:     API key + JWT (Web Crypto, zero Node.js deps)

Packages

Package Purpose
@edgemail/core Database (78 methods), receiver, sender, scheduler, auth, migrations
@edgemail/api Hono REST router (67 endpoints) + createEdgeMail() factory
@edgemail/client TypeScript API client (50+ typed methods, zero deps)
create-edgemail Interactive CLI scaffolding tool

Repositories

Repo Purpose Location
edgemail Standalone platform ~/Development/edgemail/ / Gitea
argobox Integration via @edgemail/core ~/Development/argobox/packages/edgemail-core/ (symlink)

ArgoBox Integration

ArgoBox's email system runs on @edgemail/core. The swap replaced email operations previously mixed into the AdminDatabase class (~1,797 lines spanning lines 339-2135 in the 2,151-line admin-db.ts) (which also handles pentest and infrastructure).

Component Implementation
Database layer EmailDatabase from @edgemail/core/db via email-db-adapter.ts
Email sender ArgoBox's own email-sender.ts (multi-domain Resend routing via getEnv())
Admin API POST /api/admin/email — 40+ actions (list, send, search, labels, filters, etc.)
User API POST /api/user/email — scoped to user's mailbox with ownership checks

How Changes Flow

Local development: packages/edgemail-core is a symlink to the EdgeMail repo. Changes to EdgeMail source are picked up after rebuilding (npx tsc in EdgeMail core).

Production deployment: @edgemail/core is published to Gitea's npm registry. ArgoBox pulls it as a versioned dependency during CF Pages build.

Sync Workflow

# 1. Edit EdgeMail
cd ~/Development/edgemail/packages/core/src
# make changes...

# 2. Rebuild
npx tsc

# 3. ArgoBox picks it up instantly (symlink)
# For production: bump version + npm publish + push ArgoBox

Database Schema (14 tables + 1 FTS5 virtual table)

  • emails — message storage (inbox, sent, drafts, archive, trash)
  • email_mailboxes — managed addresses with owner_email
  • email_attachments — metadata + R2 keys
  • email_contacts — auto-populated address book
  • email_labels + email_label_map — user-defined tagging
  • email_filter_rules — condition/action automation
  • email_autoresponders — vacation replies
  • email_scheduled — future send queue (cron-driven)
  • email_blocked_senders — spam blocking
  • email_templates — reusable email templates
  • email_aliases — address forwarding rules
  • email_custom_folders — user-created folders with owner scoping
  • emails_fts — FTS5 full-text search index
  • _edgemail_migrations — schema versioning

Test Suite

143 tests across 5 files, all using Miniflare (real D1/R2 bindings, no mocks):

File Tests Scope
db.test.ts 35 Every D1 table CRUD operation
auth.test.ts 13 API key + JWT lifecycle
integration.test.ts 29 Cross-module email pipeline
http-api.test.ts 54 All REST endpoints through Hono
resend-live.test.ts 12 Real Resend API sends (requires keys)
cd ~/Development/edgemail/packages/core
npx vitest run          # 131 tests (no API keys needed)
npx vitest run src/__tests__/resend-live.test.ts  # +12 live tests (needs .env)

Key Numbers

Metric Value
TypeScript ~9,200 lines
EmailDatabase methods 78
API endpoints 67
D1 tables 14
Tests 143
Runtime deps 2 (postal-mime, hono)
Platform cost $0-5/month

Credentials

Resend API keys for outbound email:

  • RESEND_API_KEY — primary (argobox.com domain)
  • RESEND_LAFORCEIT_API_KEY — secondary (laforceit.com domain)

Keys stored in ArgoBox vault credentials. Test keys loaded from packages/core/.env (gitignored).

edgemailemailcloudflareworkersd1serverlessresend