# Temp Mail Management

The Temp Mail admin section allows you to manage catch-all email domains, configure global settings, and monitor temporary email usage across all workspaces.

Access it via Admin Panel > System > Temp Mail.

## Domains Tab

This tab shows all configured temp mail domains in an accordion layout. Each domain can be expanded to edit its settings.

### Domain Fields

Field | Required | Description
--- | --- | ---
Domain | Yes | The domain name (e.g., `tmpmail.yoursite.com`). Must be unique.
Display Name | Yes | Friendly name shown in the admin panel.
IMAP Host | Yes | IMAP server hostname (e.g., `mail.yoursite.com`).
IMAP Port | Yes | Usually 993 (SSL) or 143 (STARTTLS).
IMAP Username | Yes | Login username for the catch-all mailbox.
IMAP Password | Yes | Login password. Encrypted at rest. Leave blank on edit to keep existing.
Encryption | Yes | SSL, TLS, or None.
Default Lifetime | Yes | Default address lifetime in hours if the plan doesn't specify one. Range: 1-8760 (1 year).
Max Addresses | No | Global cap on total active addresses for this domain. Leave empty for unlimited.
Blocked Patterns | No | Comma-separated keywords to block in local-part generation (e.g., "admin, postmaster, abuse, root").

### Domain Actions

- Toggle Active/Inactive: Click the switch on the right side of the domain header. Inactive domains stop syncing and stop accepting new address generation.
- Test Connection: Click "Test Connection" inside the expanded domain to verify IMAP connectivity. Shows success (folder count) or error message.
- Sync Now: Manually trigger an immediate sync for this domain. Useful for testing.
- Save: Save changes to the domain configuration.
- Delete: Delete the domain. Only works if no active addresses exist on it.

### Domain Status

- Active — Domain is syncing and accepting new addresses.
- Inactive — Domain is disabled. No syncing, no new addresses.
- Error — IMAP connection failed. Check the error message and fix credentials.

## Settings Tab

Global settings that apply to all temp mail domains and addresses.

Setting | Default | Description
--- | --- | ---
Temp Mail Enabled | ON | Master kill switch. When OFF, no user can generate temp addresses regardless of plan.
Default Lifetime (hours) | 24 | Fallback lifetime when neither the plan nor the domain specifies one.
Auto-Cleanup After (days) | 30 | Number of days after expiry to permanently (force) delete soft-deleted addresses.
Blocked Keywords | Empty | Global comma-separated keywords blocked in all address generation.

## Plan Configuration

Temp Mail limits are configured per plan in Admin > Plans > Edit Plan:

1. Go to the Feature Access tab and enable the "Temp Mail" toggle.
2. Go to the Resource Limits tab and set:
   - Temp Mail Addresses — Maximum active addresses per workspace. Check "Unlimited" for no cap.
   - Temp Mail Lifetime (Hours) — Maximum hours an address stays active. This overrides the domain/global default.

### Recommended Plan Configuration

Plan | Temp Mail | Addresses | Lifetime
--- | --- | --- | ---
Free | OFF | — | —
Starter | ON | 2 | 1 hour
Pro | ON | 10 | 24 hours
Enterprise | ON | Unlimited | 720 hours (30 days)

## Monitoring & Maintenance

### Stats Visible in Admin

- Total Domains: Number of configured domains.
- Active Domains: Domains currently syncing.
- Total Active Addresses: Count of active, non-expired temp addresses across all workspaces.
- Last Synced: Timestamp of the most recent successful sync per domain.

### Useful Artisan Commands

    # Check sync status
    php artisan mailtrixy:sync-temp-mail --force

    # Preview cleanup
    php artisan mailtrixy:cleanup-temp-mail --dry-run

    # Check scheduler is running
    php artisan schedule:list

### Log Monitoring

Temp Mail operations are logged at these levels:

- `INFO` — Successful syncs with message counts.
- `ERROR` — Failed IMAP connections, sync failures.
- `INFO` — Cleanup results (addresses deactivated, messages deleted).

Check `storage/logs/laravel.log` and search for `[Scheduler] sync-temp-mail` or `[Scheduler] cleanup-temp-mail`.