Skip to content
johnwmailPublic

About

Modern webmail app support gpg encryption

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

e2mail

Self-hosted, end-to-end encrypted e2Mail client. Speaks IMAP/SMTP to any mail provider, stores PGP key material in a single SQLite file, and serves the SPA and the API from a single Go binary in one container.

Features

  • Any IMAP/SMTP server — Gmail, Outlook, Fastmail, iCloud, QQ, custom domains, or a self-hosted mail server. Built-in adaptive table for common providers.
  • Multi-account — manage multiple mail accounts in one session, with a Thunderbird/iOS-Mail-style sidebar folder tree, per-account unread badges, and a /accounts management page. Account IMAP/SMTP passwords are stored encrypted at rest (LUKS-style envelope encryption: a random DEK wraps all account passwords, itself wrapped by the first account's IMAP password).
  • End-to-end PGP (OpenPGP.js, Ed25519) — generate, import, encrypt, sign, decrypt, verify. Multi-block / multi-key / armored-or-binary .gpg files are all parsed and re-armored before send.
  • Server-side keyring — passphrases never leave the browser; the server only stores the user's Passphrase-encrypted private key blob.
  • Per-user contact keyrings stored in SQLite, shared across browsers.
  • Real-time push via IMAP IDLE → SSE on /api/events (multiplexes all accounts over a single SSE connection).
  • One-file storage — /data/e2Mail.db (with WAL siblings). Legacy per-user JSON keyring files are auto-migrated on first boot.
  • Container env defaults — IMAP/SMTP host & port can be pre-configured by the admin so users don't have to fill the advanced settings.
  • Secure by default — allowInsecureTls is off unless explicitly enabled by the server admin (MAIL_ALLOW_INSECURE_TLS); clients cannot enable it.

Web UI

Sign-in only asks for email and password; IMAP/SMTP host and port can be pre-filled by the admin through env vars, and the advanced panel stays collapsed for everyone else.

Sign-in screen

Everything account-related lives on one settings page — 2FA and password, PGP keys, mail accounts, Sieve filters, and appearance — with a sidebar on desktop and a scrollable tab strip on narrow screens.

Settings, account security section

PGP key pairs are generated in the browser and backed up to the server only in passphrase-encrypted form, so the same key can be picked up on another device without the passphrase ever being uploaded. Contact public keys are imported from files, pasted blocks, or a keyserver lookup.

Settings, PGP keys section

Several mail accounts can be managed in one session, each with its own IMAP/SMTP endpoints, TLS flags, and encrypted-at-rest password.

Settings, mail accounts section

Sieve filters are edited as visual rules, and the generated script stays visible so you can check exactly what gets uploaded to the server.

Settings, Sieve filter rule builder

Theme, interface language, and message-vs-conversation list mode are chosen under Appearance. All three are stored as server-side user preferences, so the choices follow the account to another browser or device.

Settings, appearance section

Settings in dark theme

Settings in Traditional Chinese

Every screen is built for phones as well as desktops:

Account security on a phone Sieve filters on a phone Appearance settings on a phone

Screenshots use sample accounts and keys.

Architecture

┌──────────────┐      HTTP      ┌──────────────────────────────────┐
│  Browser UI  │ ◀────────────▶ │  Single Go binary (chi) :8080     │
│  React + Vite│   /api/*       │  - serves embedded SPA (go:embed) │
└──────────────┘                │  - HTTP API                      │
                                │  - IMAP client pool + IDLE        │
                                │  - SMTP sender                   │
                                │  - Sessions (in-memory, AES)     │
                                │  - SQLite storage                │
                                └──────────────┬───────────────────┘
                                               │
                                               ▼
                                /data/e2Mail.db  (named volume)

The frontend dist/ (React 19 + Vite 8 + Tailwind 4) is built during the Docker image build and go:embed-ed into the backend binary (backend/web), so the container runs a single process serving both the SPA and the API.

Service Tech Port (host)
e2Mail Go 1.26 + chi + modernc.org/sqlite, embeds the Vite build 8080

Quick start

# Clone
git clone <repo-url> e2mail
cd e2mail

# Build & run
docker compose up -d --build

# Open
open http://localhost:8080      # e2Mail UI (SPA + API on one port)
curl http://localhost:8080/health   # health probe

On first launch, /data/e2Mail.db is created and any legacy /data/keyrings/*.json files are auto-imported into the personal_keyrings table.

Configuration

Environment variables are loaded at startup. The simplest mail setup is:

MAIL_SERVER=example.com
# If IMAP/SMTP are on a subdomain, also set:
# MAIL_IMAP_HOST=mail.example.com
# MAIL_SMTP_HOST=mail.example.com
# MAIL_ALLOWED_DOMAINS=example.com

MAIL_ALLOWED_DOMAINS defaults to MAIL_SERVER in locked mode, so it is only needed when the server host differs from the email domain.

See docs/CONFIGURATION.md for the full mail-server reference, locked/prefill behaviour, private/LAN policy and the migration table from the removed DEFAULT_* names.

Env var Default Purpose
PORT 8080 Backend HTTP listen port
DATA_DIR /data SQLite + keyring directory (must be on a persistent volume)
SESSION_TTL_HOURS 24 Idle session expiry (hours, cookie Expires/MaxAge 同步)
SESSION_MAX_AGE_HOURS 168 Absolute session lifetime (hours); re-login required even if active
SESSION_SECRET (random) 32-byte AES-GCM key for encrypting the per-session DEK at rest (raw 32 chars / base64 44 chars / hex 64 chars)
COOKIE_SECURE true Set Secure flag on e2Mail_session cookie (set false for plain HTTP dev)
HTTP_ALLOWED_HOSTS — Comma-separated hostnames the server answers to (e.g. mail.example.com); other Host values get 421. Empty = no restriction. The reverse proxy must preserve the original Host
MAIL_SERVER — Mail domain (e.g. example.com); also the default IMAP/SMTP host. Locked login server by default
MAIL_MODE auto locked = users cannot change the login server; prefill = pre-filled but editable. Auto = locked when both hosts are set
MAIL_IMAP_HOST — Operational IMAP host override (e.g. mail.example.com)
MAIL_IMAP_PORT 993 IMAP port
MAIL_SMTP_HOST — Operational SMTP host override (e.g. mail.example.com)
MAIL_SMTP_PORT 587 SMTP port
MAIL_ALLOW_INSECURE_TLS false Allow self-signed / unverified TLS for IMAP/SMTP
MAIL_ALLOWED_DOMAINS auto Comma-separated email domains allowed to sign in. Auto = MAIL_SERVER when locked; empty otherwise
MAIL_SIEVE_HOST / MAIL_SIEVE_PORT / MAIL_SIEVE_USE_TLS / MAIL_SIEVE_ALLOW_INSECURE_TLS — / 4190 / true / false Optional Sieve defaults
REQUIRE_2FA true Enforce 2FA onboarding for new logins
REQUIRE_PGP true Enforce PGP key setup onboarding for new logins
DB_BACKUP DISABLE Auto-backup SQLite to $DATA_DIR/backups/ (DISABLE / DAILY / WEEKLY / MONTHLY; see docs/BACKUP.md)
WEBAUTHN_RP_ID — Relying Party ID for passkeys (e.g. mail.example.com); feature off when unset. See docs/PASSKEY.md
WEBAUTHN_RP_ORIGINS — Comma-separated allowed origins (e.g. https://mail.example.com); must be HTTPS
WEBAUTHN_RP_NAME e2Mail Display name shown in the OS passkey prompt

The public endpoint GET /api/server-config exposes the defaults so the login page can pre-populate the advanced settings panel.

Version metadata

Version, BuildTime and CommitHash are baked in at image build time and shown in the startup log and the sidebar footer of the UI. Defaults are vdev / timeless / sha-unknown; tag builds (.github/workflows/container.yml) inject the real values via Docker --build-arg:

docker build \
  --build-arg VERSION=v1.2.3 \
  --build-arg BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
  --build-arg COMMIT_HASH=$(git rev-parse HEAD) \
  .

Storage

Everything user-private lives in one SQLite file:

  • contact_keys — per-user PGP public keys for contacts (email, fingerprint, key ID, ASCII-armored key).
  • personal_keyrings — per-user cloud-synced private keyring (passphrase- encrypted private key + public key + metadata).
  • accounts — per-user mail account settings (IMAP/SMTP host/port/TLS flags); passwords are stored encrypted with a per-user DEK.
  • users — per-user credential envelope (Argon2id salt + DEK wrapped by the master key derived from the first account's IMAP password).

WAL mode is enabled (journal_mode=WAL, busy_timeout=5000); the -shm / -wal siblings accompany the main file inside the same data named volume.

Set DB_BACKUP to DAILY, WEEKLY, or MONTHLY to take a consistent snapshot (VACUUM INTO) into /data/backups/ on each period (checked hourly; skipped if that period’s file already exists). Default DISABLE. See docs/BACKUP.md for retention, restore, and why this is not an off-volume upgrade backup.

Documentation

Per-feature design notes and implementation plans live in docs/:

Document Scope Status
LDAP.md Login password change through OpenBSD ldapd, including DEK re-wrap ordering and rollback implemented
CONFIGURATION.md Mail server env reference, MAIL_SERVER simple mode, locked/prefill, login domains, SSRF and migration implemented
SIEVE.md ManageSieve integration and the visual rule builder implemented
THREADS.md Gmail-style conversation grouping from IMAP headers implemented
MultiAccounts.md Multiple mail accounts in one session implemented
MAIL-RENDER.md HTML mail sanitising, fit-to-width, remote-image blocking implemented
CONTACTS.md Per-user address book with vCard/CSV import draft
BACKUP.md DB_BACKUP SQLite period snapshots under $DATA_DIR/backups/ implemented
PASSKEY.md Passkey / WebAuthn as a login second factor (Face ID, device keys, security keys) implemented

Development

Backend

cd backend
go test ./...       # add tests here
go run ./cmd/server

Frontend

cd frontend
npm install
npm run dev         # http://localhost:5173, proxies /api to :8080
npm run build

http://localhost:5173/preview.html renders the settings page on its own with a stubbed session and canned API responses, so layout (including phone widths) can be checked without a backend or a real mail server. Append ?2fa=on to see the enabled-2FA state. The file is dev-only — vite build only emits index.html, so it never reaches the container image.

The README screenshots are regenerated from that preview with node scripts/screenshots.mjs (needs a running dev server and a Playwright Chromium; see the header of the script).

Security notes

  • Private keys are encrypted at rest with the user's passphrase; the server never sees the passphrase.
  • Mail account passwords are never stored in plaintext: each user has a random DEK that encrypts all account passwords, and the DEK itself is AES-GCM wrapped by a master key derived (Argon2id) from the first account's IMAP password. Losing that password permanently locks all stored account secrets.
  • Sessions hold only the in-memory DEK (AES-GCM encrypted); setting SESSION_SECRET is recommended for multi-instance deployments.
  • The session ID lives only in the HttpOnly, SameSite=Lax e2Mail_session cookie. The frontend never writes the token or session payload to localStorage; on startup it re-validates the cookie via /api/auth/me.
  • HTML mail renders inside a sandboxed iframe with its own restrictive CSP. Remote images, media, and fonts stay blocked until the user allows them — including SVG <image>, <video poster>, and inline CSS url() vectors.
  • Outbound IMAP/SMTP/Sieve connections reject private, loopback and link-local addresses for user-entered hosts. Administrator-configured MAIL_* hosts are trusted, so a LAN mail server works without an extra allow-list.
  • Attachments with active content (HTML, SVG, XML, PDF, JavaScript, …) are always sent as Content-Disposition: attachment with nosniff and a sandboxing CSP; only common raster image types may render inline.
  • TLS is mandatory by default (allowInsecureTls = false). Only enable self-signed certs via env when targeting a test environment.
  • Requests hit the Go server directly (no nginx/proxy in front), so large PGP key imports of dozens of keys aren't rejected by a proxy size limit.

License

MIT (or your preference — see LICENSE once added).

About

Modern webmail app support gpg encryption

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages