The email queue (Lovable-coupled)
Email is a PGMQ-based queue dispatched by a cron worker, entirely coupled to Lovable's proprietary services.
Flow
auth-email-hook— a Supabase Auth "Send Email" hook. Verifies a Lovable webhook signature (@lovable.dev/webhooks-js, headersx-lovable-signature/x-lovable-timestamp, secret =LOVABLE_API_KEY). Renders a React-Email template to HTML + plain text, writes apendingrow toemail_send_log(before enqueue, deliberately), thenrpc('enqueue_email', { queue_name: 'auth_emails', payload }).process-email-queue— cron worker (gateway-JWT auth). Readsauth_emailsthentransactional_emailsin priority order viaread_email_batch, sends through Lovable's email API (@lovable.dev/email-js), logssent/failed, anddelete_emailon success. DLQs:<queue>_dlqviamove_to_dlq.
Magic constants (in process-email-queue / email_send_state)
MAX_RETRIES=5, batch_size=10, send_delay_ms=200, auth_email_ttl=15min,
transactional_ttl=60min, visibility timeout vt=30s, rate-limit Retry-After=60s.
Config overridable from the singleton email_send_state (id=1). On a 429 the worker writes
retry_after_until and stops the whole run.
Safety nets
- Idempotency: a partial unique index
email_send_log(message_id) WHERE status='sent'plus a pre-send check handles visibility-timeout double-sends. - Queue RPCs are SECURITY DEFINER but
REVOKE FROM PUBLIC; GRANT service_roleonly.
Gotchas for the rebuild (target is .NET)
- Everything email is Lovable-proprietary — webhook lib, send API,
LOVABLE_API_KEY(which doubles as webhook secret). None of it survives leaving Lovable; the queue, DLQ, TTL, idempotency, and rate-limit backoff logic must be reimplemented. - Leftover identifier
SITE_NAME="open-whisper-hub"leaks into theFrom:display name (whistleblower pivot). - English
EMAIL_SUBJECTSwith Portuguese bodies. - The portal-submission notification email is an unimplemented
console.logstub.
Rebuild implication
Reimplement on the target stack (e.g. a .NET background worker + a real ESP) preserving the
queue semantics (priority, retry/DLQ, TTL, idempotency, rate-limit backoff) and the
pending-before-send audit row.