Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
12 KiB
Managed Email Domain Orchestration (EE) – Implementation Plan
Date: November 6, 2025
Authors: Codex (draft)
Status: Draft
Edition: Enterprise Only
1. Problem Statement
Alga PSA currently sends all outbound application mail from the platform’s shared Resend domain, even for hosted Enterprise tenants. Customers need to send transactional messages from their own domains without managing provider credentials or separate infrastructure. We must support tenant-managed sending domains while keeping the provider abstraction generic and future‑proof.
2. Overall Work Statement
Deliver an enterprise-only managed email domain orchestration system that lets hosted Alga PSA tenants verify and activate their own sending domains through guided DNS setup, Temporal-managed workflows, and provider-agnostic automation, ultimately enabling outbound mail to originate from tenant-branded domains without exposing provider-specific details.
3. Phased To-Do List
Phase 1 – Foundations (Services & Workflows)
- ✅ Scaffold
ee/server/src/services/email/ManagedDomainService.tswithcreateDomain,checkDnsAndProviderStatus,activateDomain,deleteDomain. - ✅ Add provider factory hook in
ee/server/src/services/email/ManagedDomainService.tsthat instantiatesResendEmailProviderviaserver/src/services/email/EmailProviderManager.tsutilities. - ✅ Create DNS lookup helper (
ee/server/src/services/email/dnsLookup.ts) to query TXT/MX/CNAME records usingdns.promises. - ✅ Register EE-only workflow actions by exporting the service through
packages/product-email-domains/ee/entry.tsand wiringshared/workflow/init/registerWorkflowActions.ts. - ✅ Implement Temporal workflow file
ee/temporal-workflows/src/workflows/managed-email-domain-workflow.tswith states/signals described in Section 7. - ✅ Add supporting activities in
ee/temporal-workflows/src/activities/email-domain-activities.ts(provision, dnsCheck, activate, cleanup) and register them inee/temporal-workflows/src/activities/index.ts. - ✅ Update
ee/temporal-workflows/src/workflows/index.tsto export the new workflow and configure the worker task queue. - ✅ Extend
ee/temporal-workflows/src/config/startupValidation.tsto require queue/env vars (EMAIL_DOMAIN_TASK_QUEUE, etc.).
Phase 2 – Application Surface (Server Actions & UI)
- ✅ Add workflow client wrapper
ee/server/src/lib/email-domains/workflowClient.ts(Temporal enqueue + signals). - ✅ Create EE server actions file
ee/server/src/lib/actions/email-actions/managedDomainActions.tsexposing add/verify/delete operations. - ✅ Update
packages/product-email-settings/ee/entry.tsxto point at a new EE component. - ✅ Build EE UI components:
ee/server/src/components/settings/email/ManagedEmailSettings.tsx(top-level tab content).ee/server/src/components/settings/email/ManagedDomainList.tsx(status table).ee/server/src/components/settings/email/DnsRecordInstructions.tsx(copyable DNS cards).
- ✅ Modify
server/src/components/settings/general/SettingsPage.tsxto load the EE package entry (ensure CE build untouched). - ✅ Update feature-flag usage or edition guards so only Enterprise tenants see the managed tab (done 2025-11-06 – outbound email UI now always renders the managed-domain card).
Phase 3 – Verification & Activation (Business Logic)
- ✅ Implement DNS propagation checks in
ManagedDomainService.checkDnsAndProviderStatususing the helper from Phase 1. - ✅ Extend
shared/workflow/init/registerWorkflowActions.tsto call ManagedDomainService (via package import) for create/verify/activate actions. - Update
ee/server/src/lib/services/TenantEmailService.tsto prioritizedefault_from_domainfrom verified managed domains when building thefromheader. - Persist analytics events (e.g.,
email_domain.verified) inee/server/src/lib/analytics/posthog.ts. - Ensure
tenant_email_settings.provider_configsgets a managed provider entry by default (updateserver/src/lib/actions/email-actions/emailSettingsActions.tsand EE override if needed).
4. Goals
- Allow Enterprise tenants to request, verify, and activate custom sending domains within the hosted environment.
- Hide vendor-specific terminology (Resend) from the tenant UI.
- Centralize provider automation in an EE-only “Managed Email Domain Service” that can work with Temporal workflows.
- Preserve pluggability so additional providers (e.g., SES, SendGrid) can be added later without UI or API churn.
Non-Goals
- Customer-managed SMTP credential onboarding (already handled today).
- Extending the feature to Community Edition.
- Immediate bounce/complaint webhook self-service (tracked separately).
5. High-Level Solution
-
Enterprise Domain Orchestration Service
- New EE service (e.g.,
ee/server/src/services/email/ManagedDomainService.ts) wrapsIEmailProviderdomain lifecycle APIs (create, verify, delete). - Uses centralized credential management (Secrets) and provider configuration to instantiate the correct adapter (
ResendEmailProviderinitially). - Persists provider domain IDs, DNS instructions, and status updates in
email_domains.
- New EE service (e.g.,
-
Temporal Workflow Integration
- Create an EE workflow (
ee/temporal-workflows/src/workflows/email-domain-verification-workflow.ts) managed by the existing temporal worker. - Activities interact with the Managed Domain Service to:
- Create provider-side domain records and capture DNS requirements.
- Deliver DNS record instructions to the domain owner and monitor for propagation.
- Poll verification status / trigger verification runs.
- Activate domains post-verification (update tenant email settings, set default
fromdomain).
- Signals/events mirror the portal domain workflow (e.g., user triggers verification, DNS configured, etc.).
- Create an EE workflow (
-
Workflow Client + Actions
- Add EE workflow client utilities (
ee/server/src/lib/email-domains/workflowClient.ts) similar to custom portal domains. - Replace mock actions in
shared/workflow/init/registerWorkflowActions.tsby wiring through EE package exports:createManagedDomain→ Managed Domain ServicecreateDomain.triggerManagedDomainVerification→ fetch status via Temporal activity.activateManagedDomain→ persist as tenant default domain.
- Add EE workflow client utilities (
-
UI / Server Actions
- Introduce EE-only email settings component via package alias (
packages/product-email-settings/{oss,ee}/entry.tsx). - EE version removes direct API key inputs, surfaces DNS instructions, verification progress, and Temporal-triggered statuses.
- Server actions (
ee/server/src/lib/actions/email-actions/managedDomainActions.ts) call workflow client and Managed Domain Service. - CE retains existing manual flows through OSS package exports.
- Introduce EE-only email settings component via package alias (
-
Tenant Email Sending
- Adjust EE override of
TenantEmailServiceto prioritize verified tenant domain forfromheaders and to initialize the managed provider when available. - Preserve fallback to platform default when no verified domain exists.
- Adjust EE override of
6. Architecture Overview
Tenant UI (Email Settings - EE package)
│
├── EE server actions (managedDomainActions.ts)
│ │
│ ├── Workflow Client → Temporal Workflow
│ │ ├── Activities → Managed Domain Service → Provider Adapter (Resend)
│ │ └── DB updates via shared models
│ └── Direct Managed Domain Service calls (e.g., read status)
│
└── tenant_email_settings / email_domains tables
│
└── TenantEmailService (EE override) selects verified domain for outbound mail
7. Temporal Workflow Design
- Workflow Name:
managedEmailDomainWorkflow - Queue: reuse temporal worker (e.g.,
email-domain-workflowstask queue). - Inputs:
{ tenantId, domainName, trigger }(trigger =register,refresh,delete). - States:
created,awaiting_dns,verifying,verified,failed,deactivated. - Signals:
dnsConfigured– domain owner confirms DNS records were created.refreshStatus– admin requests immediate re-check.
- Activities:
provisionProviderDomain– call Managed Domain ServicecreateDomain, store provider IDs and DNS instructions, surface instructions to the tenant (UI + email).checkDnsAndVerificationStatus– verify DNS propagation (e.g., public TXT/MX/CNAME lookup) and poll provider status; update DB and determine next step.activateTenantDomain– mark domain verified, updatetenant_email_settings.default_from_domain, push analytics event.cleanupProviderDomain(future) – delete domain if tenant removes it.
- Retries/Error Handling:
- Exponential backoff for provider API rate limits.
- Max runtime guard (e.g., 7 days) before failing workflow and surfacing instructions to support.
8. Data & Persistence
- Reuse existing
email_domainscolumns (provider_id,provider_domain_id,dns_records,status,failure_reason). - Add structured metadata (JSON) for Temporal workflow execution ID and audit trail.
- Ensure
tenant_email_settings.provider_configsincludes a managed provider config template (no per-tenant API key). - Set
default_from_domainto verified domain when activation completes; store previous domain for rollback.
9. UI/UX Updates (EE)
- Tabs in Email Settings:
- “Managed Sending” (EE): wizard to add domain, display DNS records, track status.
- “Other Providers” (legacy): optional view for SMTP credentials.
- Show DNS records grouped by type with copy-to-clipboard; emphasize that verification may take time.
- Expose workflow status messages (e.g., “Waiting for DNS”, “Verification in progress”).
- Provide manual “Retry verification” button that triggers
refreshStatussignal. - Remind domain owners about required DNS updates with contextual help, links to registrar guides, and status badges that indicate whether DNS records are detected yet.
10. Work Breakdown
- Planning/Infra
- Finalize workflow name/queue configuration and secrets usage.
- Define naming convention for generated sender addresses (e.g.,
notifications@{tenantDomain}).
- Backend Foundations
- Implement Managed Domain Service with provider factory.
- Wire up Temporal workflow and activities within the existing worker harness.
- Update workflow action registry via EE package export.
- Server Actions & APIs
- Add EE actions for create/verify/delete domain; update GraphQL/REST endpoints if applicable.
- Ensure CE stubs return current behavior.
- UI Layer
- Build EE Email Settings component; update package alias resolution and feature flag gating.
- Adjust CE UI to hide managed-domain features.
- Add analytics events for domain lifecycle milestones.
11. Risks & Mitigations
- Provider API Limits: Add retry/backoff strategy, monitor via logs.
- DNS Verification Delays: Provide clear instructions, surface TTL expectations, allow manual retries.
- Temporal Worker Load: Reuse existing worker but ensure queue isolation and metric dashboards.
- Multi-Provider Future: Keep service provider-agnostic, encapsulate provider selection logic.
- Tenant Misconfiguration: Validate domain format, restrict apex records, provide warnings before activation.
12. Open Questions
- Do we allow tenants to rename the default sender mailbox per domain?
- Should we automatically notify support when a domain stalls in verification beyond N hours?
- How do we handle domain deletion if messages are in-flight (grace period vs. immediate removal)?
13. Next Steps
- Engineering sign-off on workflow + service design.
- Break out Phase 1 tasks into individual tickets with resource assignments.
- Align UI/UX specifications for the managed email settings components before Phase 2 begins.