๐ง Email Alias Quick Start
Generate and manage email aliases to receive purchase orders via inbound email.
๐ Quick Start (3 Steps)
Section titled โ๐ Quick Start (3 Steps)โ1. Select Your ERP Connection
Section titled โ1. Select Your ERP ConnectionโOpen the webapp Settings โ Email Intake page (or query erp_connections in Postgres) and select the active ERP connection for your organization.
2. Generate Aliases
Section titled โ2. Generate AliasesโCreate aliases from the webapp Settings UI or via the /api/alias/* API routes (apps/webapp/src/pages/api/alias/):
POST /api/alias/generateโ Generates the organization alias and member aliases for the selectederpConnectionIdGET /api/aliasโ Lists existing aliases for the organizationPOST /api/alias/verifyโ Verifies an email alias token
3. Verify Emails
Section titled โ3. Verify EmailsโVerification emails are automatically sent to each alias address. Users can click the verification link to activate, or admins can verify an alias directly using the @repo/db CLI script:
pnpm --filter @repo/db verify-email-alias <alias-email-or-id>๐ What This Creates
Section titled โ๐ What This CreatesโFor an organization named โGenFitโ:
- Organization alias:
orders+genfit@ordermatic.co- Receives emails for entire organization
- Member aliases:
orders+genfit_johnsmith@ordermatic.co- One for each organization member
- Format:
{org-slug}_{firstname}{lastname}
๐ Check Alias Status
Section titled โ๐ Check Alias Statusโ# View aliases in databasepsql "$DATABASE_URL" -c \ "SELECT email, status, verified_at FROM email_aliases WHERE erp_connection_id = 'your-connection-id';"๐งช Test
Section titled โ๐งช Testโ- Send email to an alias (e.g.,
orders+genfit@ordermatic.co) - Watch logs: webapp / Temporal logs will show email processing
- Verify: Order should be created in your system
๐ Full Documentation
Section titled โ๐ Full Documentationโ- Email body extraction flow (archived design record): email order processing integration
๐ ๏ธ Database Scripts & API Routes
Section titled โ๐ ๏ธ Database Scripts & API Routesโ# Manually verify an email alias via @repo/db scriptpnpm --filter @repo/db verify-email-alias
# Migrate email alias domains (e.g. legacy domain -> ordermatic.co)pnpm --filter @repo/db migrate-email-aliases-domainWebapp API routes (apps/webapp/src/pages/api/alias/):
POST /api/alias/generateGET /api/aliasPOST /api/alias/verifyDELETE /api/alias/[id]
๐ Common Issues
Section titled โ๐ Common IssuesโโUnauthorizedโ Error
Section titled โโUnauthorizedโ Errorโ- Sign in to the webapp with an active Clerk organization selected
- Make sure
CLERK_SECRET_KEYis set in your local environment
Emails Not Sending
Section titled โEmails Not Sendingโ- Check
RESEND_API_KEYin your local environment - Verify
WEBAPP_URL/APP_URLis set if you need generated verification links to use a public URL
No Aliases Created
Section titled โNo Aliases Createdโ- Check
DATABASE_URLis correct - Verify webapp is running:
curl http://localhost:4321/api/health
Database Auth Failed
Section titled โDatabase Auth FailedโUpdate DATABASE_URL in .env with valid PostgreSQL credentials.
๐ How It Works
Section titled โ๐ How It WorksโThe alias generation flow:
- Authenticates the caller and organization context via Clerk
- Calls the webapp
/api/alias/*routes for the organizationโserpConnectionId - Generates aliases for the organization and members in
email_aliases - Sends verification emails (or activates via
pnpm --filter @repo/db verify-email-alias)
โ Next Steps After Alias Generation
Section titled โโ Next Steps After Alias Generationโ- Send test email to an alias to verify the end-to-end flow
- Monitor processing in webapp / Temporal logs