- Add OAuthCredential model for storing Google/Microsoft OAuth tokens - Add email provider auto-detection endpoint (Gmail, Outlook, Yahoo, etc.) - Add EmailConfigWizard frontend component with step-by-step setup - Add OAuth flow endpoints for Google and Microsoft XOAUTH2 - Update production settings to make AWS, Sentry, Mailgun optional - Update Traefik config for wildcard subdomain routing - Add logo resize utility script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
4.4 KiB
4.4 KiB
Email Configuration Wizard Plan
Overview
Create a step-by-step wizard for configuring email settings with:
- Auto-detection of IMAP/SMTP settings from email address
- OAuth support for Gmail accounts
- Manual configuration fallback
Wizard Steps
Step 1: Email Address Entry
- User enters their support email address (e.g., support@company.com)
- System extracts domain and attempts auto-detection
- Shows detected provider (Gmail, Outlook, Yahoo, custom domain)
Step 2: Authentication Method Selection
- For Gmail: Show "Connect with Google" OAuth button
- For Outlook/Microsoft 365: Show "Connect with Microsoft" OAuth button
- For others: Show manual configuration option
Step 3a: OAuth Flow (Gmail/Microsoft)
- Redirect to OAuth provider
- Request mail scopes (IMAP, SMTP access)
- Store OAuth tokens for authentication
- Auto-configure IMAP/SMTP settings
Step 3b: Manual Configuration
- Pre-fill detected IMAP/SMTP settings
- Allow user to modify if needed
- Password/app-specific password entry
Step 4: Test & Verify
- Test IMAP connection
- Test SMTP connection
- Show success or troubleshooting steps
Step 5: Additional Settings
- From name configuration
- Check interval
- Delete after processing toggle
Email Provider Database
Common providers with auto-detection:
| Domain | Provider | IMAP Host | IMAP Port | SMTP Host | SMTP Port | OAuth |
|---|---|---|---|---|---|---|
| gmail.com | Gmail | imap.gmail.com | 993 | smtp.gmail.com | 587 | Yes |
| googlemail.com | Gmail | imap.gmail.com | 993 | smtp.gmail.com | 587 | Yes |
| outlook.com | Microsoft | outlook.office365.com | 993 | smtp.office365.com | 587 | Yes |
| hotmail.com | Microsoft | outlook.office365.com | 993 | smtp.office365.com | 587 | Yes |
| live.com | Microsoft | outlook.office365.com | 993 | smtp.office365.com | 587 | Yes |
| yahoo.com | Yahoo | imap.mail.yahoo.com | 993 | smtp.mail.yahoo.com | 587 | No |
| icloud.com | Apple | imap.mail.me.com | 993 | smtp.mail.me.com | 587 | No |
| aol.com | AOL | imap.aol.com | 993 | smtp.aol.com | 587 | No |
For custom domains: Use MX record lookup to detect if hosted by Gmail/Microsoft
Backend Changes
New API Endpoints
-
POST /api/tickets/email-settings/detect/- Input:
{ email: "support@company.com" } - Output: Detected provider info and suggested settings
- Input:
-
POST /api/tickets/email-settings/oauth/google/- Initiate Google OAuth flow for Gmail access
-
POST /api/tickets/email-settings/oauth/google/callback/- Handle OAuth callback, store tokens
-
POST /api/tickets/email-settings/oauth/microsoft/- Initiate Microsoft OAuth flow
-
POST /api/tickets/email-settings/oauth/microsoft/callback/- Handle Microsoft OAuth callback
Model Changes
Add to TicketEmailSettings:
oauth_provider: CharField (google, microsoft, null)oauth_access_token: TextField (encrypted)oauth_refresh_token: TextField (encrypted)oauth_token_expiry: DateTimeFielduse_oauth: BooleanField
OAuth Scopes Required
Google Gmail API:
https://mail.google.com/(full mail access for IMAP/SMTP)- OR use Gmail API directly instead of IMAP
Microsoft Graph API:
https://outlook.office.com/IMAP.AccessAsUser.Allhttps://outlook.office.com/SMTP.Send
Frontend Components
EmailConfigWizard.tsx
Main wizard component with step navigation
Steps:
- EmailAddressStep - Email input with domain detection
- AuthMethodStep - OAuth vs manual selection
- OAuthConnectStep - OAuth flow handling
- ManualConfigStep - IMAP/SMTP form fields
- TestConnectionStep - Connection testing
- FinalSettingsStep - Additional options
Implementation Order
- Backend: Email provider detection endpoint
- Frontend: Wizard UI with steps
- Backend: Google OAuth integration
- Frontend: OAuth flow handling
- Backend: Microsoft OAuth integration
- Testing and refinement
Questions to Resolve
-
Should we use IMAP/SMTP with OAuth tokens, or switch to Gmail/Graph API?
- IMAP/SMTP with XOAUTH2 is simpler, works with existing code
- API approach is more modern but requires rewriting email fetcher
-
Store OAuth tokens in TicketEmailSettings or separate model?
- Same model is simpler
- Separate model allows multiple OAuth connections
-
How to handle token refresh?
- Background task to refresh before expiry
- Refresh on-demand when making email requests