16 Commits

Author SHA1 Message Date
15021a115e fix(deploy): wire AUTO_APPROVE_FREE_PROVIDERS into compose.scribase-mail.yml
env.js and waitlist-auto-approve-service.ts (526d6a9) already consume
AUTO_APPROVE_FREE_PROVIDERS and AUTO_APPROVE_FREE_PROVIDER_DAILY_CAP, but
the web service's environment allowlist in
deploy/compose.scribase-mail.yml never listed either var, and there is
no env_file fallback in this manifest. Setting them in deploy/.env alone
was a no-op: docker compose would not forward them into the container,
Zod would fall back to its "false" default, and free-provider
auto-approval stayed permanently off regardless of the env file.

Add both vars to the web service's environment block (default false /
10, matching the Zod schema defaults) and document them in
deploy/.env.example next to the existing AUTO_APPROVE_WAITLIST pair.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-04 23:26:48 +03:00
2734f9183a docs(deploy): fix stale Resend-compat API coverage claim
DEPLOY.md's "Implemented so far" line still described the API as it was at
the initial skeleton commit (POST/GET /emails only) and claimed
attachments[].path/content_type/content_id return a 422 "not yet supported" -
all three have been fully implemented (with SSRF-guarded URL fetching for
path) since the Round 1a merge. Only topic_id is actually unsupported.

This matters for distribution: the product's whole pitch is "switch from
Resend with one line," and the deploy doc customers read to evaluate
migration was understating the real API surface (domains, api-keys,
webhooks, broadcasts, audiences/contacts, segments, contact-properties,
topics, templates, suppressions, logs, metrics, inbound mail - none of which
were mentioned at all) and incorrectly telling them a commonly-used Resend
field (attachment by URL) isn't supported when it is.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-21 16:28:51 +03:00
cd1bf530ce feat(waitlist): auto-approve sign-ups from company domains with MX
On the hosted instance (IS_CLOUD) a new or waitlisted user is let in
automatically when their verified account email is on a business domain:
not a free/consumer provider, not a disposable inbox (CC0 list from
disposable-email-domains), with a usable MX record (3 s timeout, null MX
and IP/localhost exchanges rejected). One account per domain (DB check +
Redis claim) and a daily cap (AUTO_APPROVE_DAILY_CAP, default 25).
Everything fails closed to the existing waitlist flow.

Opt-in via AUTO_APPROVE_WAITLIST (default off). Approval only clears
User.isWaitlisted, so warm-up caps, reputation auto-pause, content
screening and the review queue still apply to new teams. Decisions are
logged, recorded in the admin team's audit log and mailed to the admin.
The waitlist form re-checks the account email (never the self-declared
domain) and sends approved users straight to the dashboard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 04:35:08 +03:00
c71493dcba docs(deploy): record live Dodo meter, products and webhook ids
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 02:37:19 +03:00
e128521c05 fix(mx): do not bind the submission proxy on the inbound MX port
With INBOUND_ENABLED the process started the authenticated submission
proxy on 25/587/2587 first, so the inbound MX failed with EADDRINUSE and
port 25 served the relay instead of the MX. The submission proxy now
skips the inbound port, and SUBMISSION_ENABLED=false (set for the mx
compose service) runs the container as a pure MX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 02:26:33 +03:00
503479e4ea fix(webhooks): block private and internal webhook URLs (SSRF) and null creator for API-created webhooks
Webhook deliveries are POSTed from inside the deployment network and the
response body is stored in the delivery log, so a customer URL pointing at
169.254.169.254, Redis, Postgres or another container could read internal
services. URLs are now checked on create, update and again at send time
(DNS may change): http(s) only, no credentials, no localhost, and every
resolved address must be public. WEBHOOK_ALLOWED_PRIVATE_HOSTS exempts
named internal hosts for operator smoke tests.

Webhooks created through the Resend API passed userId 0 into
createdByUserId, which violates the User foreign key; store null instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 01:43:56 +03:00
f39fe24f60 fix(deploy): pass INBOUND_INTERNAL_SECRET and INBOUND_MX_HOSTNAME to the web service
The mx service authenticates to /api/internal/inbound* with the shared
secret, but the web container never received it, so every inbound mail
was refused with 503.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 01:22:24 +03:00
6f39776933 feat: Wave 3 C1/C2 — inbound MX server and received email API
Adds Resend "Receiving emails" parity:

**C1 — Inbound MX server (apps/smtp-server/src/inbound/)**
- Port-25 SMTP listener in `inbound/server.ts`; started when `INBOUND_ENABLED=true`
- `mailauth` (MIT) for SPF/DKIM/DMARC/ARC verification; drops DMARC-reject failures
- OCI Object Storage (raw .eml + attachments) with local-disk fallback via `INBOUND_STORAGE_DIR`
- Optional ClamAV scan via `CLAMD_HOST`; non-blocking (fail-open on timeout)
- Per-IP connection limit (`INBOUND_MAX_CONNECTIONS_PER_IP`)
- Recipient domain allowlist polled from web app every 5 minutes; rejects unknown domains (550)
- Internal HTTP relay via `api-client.ts` to `POST /api/internal/inbound`

**C2 — Received email API + dashboard**
- `webhook-events.ts`: adds `email.received` event with `ReceivedEmailPayload`
- `received-email-service.ts`: persist + query received emails; `email.received` webhook dispatch
- `inbound-storage-service.ts`: signed OCI PAR download URLs for attachments
- `domain-receiving.ts`: MX record helper; toggle receiving; injected into `buildDnsRecords`
- `POST /api/internal/inbound` + `GET /api/internal/inbound/domains` (shared-secret protected)
- Resend-compat routes: `GET /emails/received`, `/emails/received/:id`, `/emails/received/:id/attachments`, `/emails/received/:id/attachments/:aid`
- tRPC `receivedEmail` router (list, get, setReceiving) for dashboard
- Dashboard `/receiving` page with table + sandboxed HTML preview; no remote loads

**Deploy docs + compose**
- `docker/Dockerfile.mx`: slim MX service image
- `compose.scribase-mail.yml`: `mx` profile service on `0.0.0.0:25`; notes OCI firewall + DNS
- `DEPLOY.md`: Inbound MX section (DNS, OCI security list, grey-cloud record, start command)
- New env: `INBOUND_INTERNAL_SECRET`, `INBOUND_MX_HOSTNAME`

**Tests**
- `auth-check.unit.test.ts`: SPF/DKIM/DMARC result parsing (mailauth mocked)
- `storage.unit.test.ts`: local-disk fallback write/read
- `received-email-service.unit.test.ts`: persist, query, pagination, error paths (Prisma mocked)
- `received.api.test.ts`: GET list/detail/attachments against Hono in-process (db mocked)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:55:11 +03:00
7ab9e69ef5 merge: content screening and first-sends review queue
# Conflicts:
#	apps/web/prisma/schema.prisma
#	deploy/.env.example
#	deploy/DEPLOY.md
#	deploy/compose.scribase-mail.yml
2026-10-07 03:40:32 +03:00
9550a5a6e6 merge: Dodo billing replacing Stripe
# Conflicts:
#	deploy/.env.example
#	pnpm-lock.yaml
2026-10-07 03:38:59 +03:00
54dd043c8f feat: content screening and admin review queue for outgoing mail
Every email (API, SMTP proxy, campaigns, scheduled) now passes one send
gate in the queue worker right after the limit check:

- ContentScreeningService: extracts all links (href/src/action, bare URLs,
  redirect/tracking-wrapped targets) and checks them against a threat-feed
  host index (default: Phishing.Database active phishing domains, MIT),
  stored in Redis as a ~3 MB sorted hash index and refreshed every 6h by
  a BullMQ job. Shared platforms are exempt from feed matches.
- In-process heuristics: blocked attachment types (.exe/.js/.scr/.iso/...),
  raw-IP links, URL shorteners, link-text/href domain mismatch,
  javascript:/data: links, base64-only bodies, missing unsubscribe on
  marketing mail, phishing/crypto/gift-card language, caps, hidden text.
- Verdicts: allow / hold / reject. Rejections return a clear 400 on the
  API/SMTP path and refuse campaigns at schedule time; malicious rejects
  are strikes and 3 in 7 days block the team.
- First-sends review: new cloud teams' emails are HELD until 20 sent and
  48h old (configurable in sending-policy.ts / env), unless verified or
  trusted (Team.sendingTrustedAt).
- New EmailStatus HELD + EmailReview table; customers see HELD in logs
  and GET /v1/emails/{id} (latestStatus); admin is emailed (rate-limited).
- Admin > Review (/admin/review, adminReview tRPC router): sandboxed
  CSP-locked preview, approve / approve and trust / approve team / reject
  (note) / reject and block team.
- Cleanup job keeps bodies of HELD emails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:38:20 +03:00
3d12afd5c2 docs: Caddy host and deploy notes for the Resend-compatible API
- deploy/scribase-mail.caddy: mail-api.scribase.com site block that rewrites
  every path to /api/resend{uri}, so Resend SDKs use the host root as baseUrl
  and nothing else of the app is exposed there. Single-level subdomain
  because Universal SSL and the *.scribase.com Origin CA cert do not cover
  api.mail.scribase.com. Validated with infra-box caddy/test/validate.sh.
- DEPLOY.md: DNS precondition, host table, SDK smoke test (Node and Python
  base URL env vars), sending-only key semantics, 10 req/s default.
- API_RATE_LIMIT example/compose default 2 -> 10 to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:37:26 +03:00
045cb046ad feat: replace Stripe billing with Dodo Payments
- Plans FREE / PRO ($20, 50k/mo, 10 domains) / SCALE ($90, 100k/mo,
  1,000 domains) with $0.90 per 1,000 overage, defined once in
  packages/lib/src/constants/pricing.ts and used by PLAN_LIMITS, the
  billing UI and the marketing pricing section
- Dodo checkout sessions, customer portal, prorated plan change,
  cancel/resume at period end (official dodopayments SDK)
- /api/webhook/dodo verified with Standard Webhooks via SDK unwrap();
  idempotent per webhook-id (BillingWebhookEvent claim and billing writes
  in one transaction); handles subscription active/renewed/plan_changed/
  on_hold/cancelled/failed/expired and payment succeeded/failed; ignores
  other products on the shared Dodo business
- Usage job ingests daily sent-email counts as Dodo usage events with
  deterministic ids (team + day), 3-day catch-up, 1,000-event batches
- Migration: Plan BASIC -> PRO, add SCALE; Team.stripeCustomerId ->
  billingCustomerId; provider-neutral Subscription (provider, customerId,
  plan, productId/productIds)
- Remove stripe package, Stripe route and STRIPE_* env; add DODO_* env,
  compose/.env.example entries and owner steps in deploy/DEPLOY.md
- Billing UI degrades to "Billing not configured" without keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:30:53 +03:00
9eca01d320 feat: near-real-time delivered/bounced/complained events from OCI Email Delivery logs
Resend parity for delivery outcomes. OCI Email Delivery writes one
OutboundRelayed service-log record per recipient (relay, bounce, complaint);
a new one-minute BullMQ job reads them through the OCI Logging Search API
(no Connector Hub push: Notifications HTTPS caps at 60 msgs/min per topic)
and feeds Delivery / Bounce / Complaint events through processEmailEvent.

- Provider: ensureDeliveryLogs (idempotent, cached) creates the
  "scribase-mail" log group and emaildelivery service logs
  (outboundrelayed, outboundaccepted) per ACTIVE email domain;
  listDeliveryEvents runs a compartment-scoped Logging Search
  (oci-logging / oci-loggingsearch 2.142.2).
- Job provider-delivery-log-poll: appSetting cursor with 10 min overlap,
  1 day max lookback, ProcessedProviderLogEvent dedupe table (pruned after
  3 days), truncation-safe cursor, enables logs on verified domains with a
  30 min back-off on failures. DELIVERY_LOG_POLL_CRON default every minute.
- relay -> DELIVERED, bounce hard/soft -> Permanent/Transient with category,
  code and SMTP status, complaint -> COMPLAINED; open/click/unsubscribe ignored.
- processEmailEvent skips a Delivery/Bounce/Complaint already recorded for
  the same recipient (log poll vs suppression poll), counts usage once per
  email and only adds hardBounced when a soft bounce turns permanent.
- Domain create/verify call ensureDeliveryLogs without failing on errors.
- Docs: IAM policy (manage log-groups, read log-content), env vars.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:18:55 +03:00
e281ca03ac feat: abuse controls for the shared OCI tenancy
- Cloud mode on in deploy (IS_CLOUD build arg): sign-ups without an
  invite are waitlisted until the admin approves them; ADMIN_EMAIL required
- Warm-up daily caps by team age (50/200/1k/5k, plan limit after 30 days),
  skipped for admin-verified teams
- Reputation guard job (every 10 min, 7-day window): warn at 2% hard
  bounce / 0.05% complaint, pause at 4% / 0.1% (min 2 complaints);
  records blockedReason/blockedAt and notifies team + admin
- Admin: block reason shown and kept in sync, team cache invalidated,
  re-waitlisting an owner blocks their teams' sending
- System mail always relays through OCI when FROM_EMAIL is set (cloud
  mode previously fell through to the upstream useSend cloud client)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 03:04:45 +03:00
f0ceeaa2e0 feat: Scribase Mail branding, docs, deploy prep and AGPL notices
- rename product to Scribase Mail across web app, emails, marketing and docs
- new monochrome mark/favicons and neutral black/white theme; remove emoji UI
- source code link (AGPL-3.0) in sidebar, login and unsubscribe pages
- rewrite marketing site and self-hosting docs for OCI Email Delivery,
  add OCI notes page (event sources, unavailable features)
- add NOTICE and MERGE.md crediting useSend and listing changes
- add deploy/compose.scribase-mail.yml (web+postgres+redis, 1.47 GB limits),
  deploy/.env.example, Caddy site and DEPLOY.md for mail.scribase.com
- replace legacy provider env vars in turbo.json, CI, env examples, docker files
- OCI SDK packages as server externals for the standalone build

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 01:57:04 +03:00