Skip to main content

Environment Variables

CAFH Platform uses environment variables for configuration. Create a .env file in the project root to customize your instance.

Required Variables

SMTP Configuration

Email functionality requires SMTP server configuration:
.env
# SMTP Configuration for cPanel
SMTP_HOST=mail.yourdomain.com
SMTP_PORT=465
SMTP_USER=[email protected]
SMTP_PASS=your_password
SMTP_SECURE=true

# Throttling Configuration
MAX_EMAILS_PER_HOUR=80
SMTP_HOST
string
required
Your SMTP server hostnameExamples:
  • cPanel: mail.yourdomain.com
  • Gmail: smtp.gmail.com
  • SendGrid: smtp.sendgrid.net
  • Mailgun: smtp.mailgun.org
SMTP_PORT
number
required
SMTP server portCommon ports:
  • 465 - SSL/TLS (recommended)
  • 587 - STARTTLS
  • 25 - Unencrypted (not recommended)
SMTP_USER
string
required
SMTP authentication username (usually an email address)
SMTP_PASS
string
required
SMTP authentication password
Never commit your .env file to version control. Add it to .gitignore.
SMTP_SECURE
boolean
required
Enable SSL/TLS encryption
  • true - Use SSL/TLS (port 465)
  • false - Use STARTTLS (port 587)
MAX_EMAILS_PER_HOUR
number
default:"80"
Maximum emails to send per hour (throttling)Prevents hitting provider limits and maintains good sender reputation.

SMTP Provider Examples

.env
SMTP_HOST=mail.yourdomain.com
SMTP_PORT=465
SMTP_USER=[email protected]
SMTP_PASS=your_password
SMTP_SECURE=true
MAX_EMAILS_PER_HOUR=80

Development vs Production

Development (.env.local)

.env.local
# Optional: Skip SMTP in local development
# Email features will log to console instead
NODE_ENV=development

Production (.env.production)

.env.production
# Full SMTP configuration required
SMTP_HOST=mail.yourdomain.com
SMTP_PORT=465
SMTP_USER=[email protected]
SMTP_PASS=your_password
SMTP_SECURE=true
MAX_EMAILS_PER_HOUR=80

NODE_ENV=production

Verification

Test your SMTP configuration:
1

Start the server

npm run dev
2

Login as admin

Navigate to http://localhost:3000 and login with admin credentials
3

Send a test email

Go to Admin > Campaigns and create a test campaign with your email address
4

Check the queue

The email queue processes every 30 seconds. Check the console for:
[Queue Worker] Processing 1 emails...

Environment Variable Loading

The platform uses dotenv to load environment variables from .env:
server.ts
import dotenv from 'dotenv';
dotenv.config();

const transporter = nodemailer.createTransport({
  host: process.env.SMTP_HOST || "localhost",
  port: parseInt(process.env.SMTP_PORT || "465"),
  secure: process.env.SMTP_SECURE === "true",
  auth: {
    user: process.env.SMTP_USER,
    pass: process.env.SMTP_PASS,
  },
});

Troubleshooting

  • Verify your SMTP host and port are correct
  • Check if your firewall allows outbound connections on the SMTP port
  • Some ISPs block port 25; use port 587 or 465 instead
  • Double-check your username and password
  • For Gmail, ensure you’re using an App Password, not your regular password
  • For other providers, verify your credentials in their dashboard
  • Check the email queue status at /api/email/status
  • Review the console for error messages
  • Verify you haven’t exceeded MAX_EMAILS_PER_HOUR
  • Check the data.json file for queued emails

Next Steps

Running Locally

Learn about development workflows

Email Server

Understand the email queue system

SMTP Configuration

Admin guide for SMTP setup

Deployment

Deploy to production

Build docs developers (and LLMs) love