47 - SMTP Configuration
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ SMTP Configuration Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ Admin Configuration │
│ /settings/smtp │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ SMTP Settings Form │ │
│ │ │ │
│ │ SMTP Server: [smtp.gmail.com ] │ │
│ │ Port: [587 ] │ │
│ │ Username: [[email protected] ] │ │
│ │ Password: [•••••••••••• ] │ │
│ │ From Email: [[email protected] ] │ │
│ │ Use TLS: [✓] Enabled │ │
│ │ │ │
│ │ [Test Connection] [Save Settings] │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ Save with Encryption
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Database Storage │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ smtp_config table │ │
│ │ │ │
│ │ id │ smtp_server │ smtp_port │ username │ password_enc │ ... │ │
│ │ ───────────────────────────────────────────────────────────────── │ │
│ │ 1 │ smtp.gmail │ 587 │ user@... │ gAAAAB... │ │ │
│ │ (Fernet encrypted) │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
│ When Email Needed
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Email Sending Service │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 1. Load SMTP config from database │ │
│ │ 2. Decrypt password using Fernet │ │
│ │ 3. Connect to SMTP server │ │
│ │ 4. Send email with TLS │ │
│ │ 5. Log result │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ SMTP Server │ │
│ │ (Gmail, SendGrid, etc.) │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ Email Delivered │
│ to Recipient │
└─────────────────────────────────────────────────────────────────────────────┘Database Schema
smtp_config Table
Password Encryption
Fernet Encryption
Key Derivation
Email Service
Configuration Loading
Send Email Function
Test Connection
API Endpoints
Save Configuration
Test Configuration
Get Configuration (Masked)
Common SMTP Providers
Gmail
SendGrid
Amazon SES
Email Templates
Password Reset Email
Order Notification Email
Security Considerations
Password Storage
Best Practices
Practice
Implementation
Key Files Reference
File
Purpose
Last updated