# v368 — CORI Mail Custom SMTP Testing and Guarded Send Preparation

## Purpose

v368 continues the CORI Mail track after v367.1. The priority is to make company-owned email setup more real without making the user interface harder for dispatch teams.

The build adds a server-side test path for saved Custom Domain SMTP accounts. Users can save their company email credentials in Workspace Integrations, then run a connection test without sending a real email.

## What changed

- Added server-side decrypt support for saved workspace integration secrets.
- Added a Custom SMTP connection test service.
- Added a new API route to test saved Custom SMTP provider accounts.
- Updated Workspace Integrations so saved Custom SMTP accounts can be tested from the Email tab.
- Updated test results so a passing SMTP account becomes connected and enabled.
- Updated failed tests so the account is marked as error or config needed.
- Updated CORI Mail wording so users are sent to Workspace Integrations to save and test company email credentials.
- Preserved the rule that CORI can prepare email, but real sending remains locked until the user approves and the provider is connected.

## User-facing rule

CORI may not send a real email just because a connection test passes.

The correct flow is:

1. Save the email account in Workspace Integrations.
2. Test the SMTP connection.
3. Let CORI prepare the draft.
4. Let the user review the exact words.
5. Send only after a final user-approved send action is wired and enabled.

## Workspace Integrations impact

At `/company/integrations`, the Email tab now supports a more complete company email setup path:

- Save company SMTP credentials.
- Keep the SMTP password in encrypted server-side storage.
- Test the saved SMTP account.
- Show the last credential check time.
- Mark the account connected when the SMTP login works.

## CORI Mail impact

At `/cori/mail`, CORI Mail now explains that custom domain email must be saved and tested through Workspace Integrations before real sending can be enabled.

This keeps technical setup away from daily dispatch work while still giving admins a clear setup path.

## Prisma schema impact

No Prisma schema changes were added in v368.

v368 uses the schema-backed integration and CORI Mail tables introduced in v367.

## Next recommended step

After v368 passes, the next decision should be whether to:

- deepen Workspace Integrations for Twilio, Google Maps, QuickBooks, and Stripe Connect readiness, or
- continue CORI Mail by wiring approved-send execution behind a guarded provider rail.
