Email Architecture
CAFH Platform uses a queue-based email system:- Admin creates campaign → Emails added to queue
- Queue worker processes → Sends emails via SMTP
- Rate limiting → Respects hourly limits
- Logs and metrics → Track delivery and engagement
Server Implementation
Fromserver.ts:
server.ts
API Endpoints
POST /api/email/queue
Add emails to the queue:GET /api/email/status
Get queue status:Queue Worker
Processes emails every 30 seconds:server.ts
Rate Limiting
Controlled byMAX_EMAILS_PER_HOUR:
.env
- Tracks emails sent this hour
- Resets counter after 60 minutes
- Stops sending when limit reached
- Resumes next hour automatically
SMTP Providers
- cPanel
- SendGrid
- Mailgun
- Gmail
Most web hosts provide cPanel email:Typical limit: 80-100 emails/hour
Testing Email Locally
Monitoring
Checkdata.json for queue state:
data.json
Troubleshooting
Emails not sending
Emails not sending
- Check SMTP credentials
- Verify
MAX_EMAILS_PER_HOURnot exceeded - Check
data.jsonfor failed emails - Review server logs for errors
Authentication failed
Authentication failed
- Double-check username and password
- For Gmail, use App Password
- Verify SMTP host and port
- Check firewall allows outbound SMTP
Queue not processing
Queue not processing
- Ensure server is running (
npm run dev) - Check console for worker logs:
- Verify
data.jsonexists and is writable
Production Recommendations
Use a dedicated SMTP service
SendGrid, Mailgun, or AWS SES provide better deliverability and higher limits
Monitor bounce rates
Track failed deliveries and remove bounced emails from your list
Implement retry logic
Retry failed emails with exponential backoff
Add email templates
Create reusable HTML templates for campaigns
Next Steps
SMTP Configuration
Admin guide for SMTP setup
Email Campaigns
Creating and sending campaigns
Automation Workflows
Automated email sequences