mailer-advance
v10.0.1
Published
Advanced Node.js email service with dynamic SMTP configuration, multi-database support (MongoDB/SQL), and a built-in UI.
Maintainers
Readme
🚀 mailer-advance v10.0
mailer-advance is a high-performance Node.js email engine with absolute flexibility. It features dynamic SMTP hot-swapping, multi-DB persistence, and a premium "management-in-a-box" UI.
⚡ Quick Start: Get Running in 60 Seconds
- Install:
npm install mailer-advance - Configure: Set
DB_URIin your.env. - Launch:
import { DatabaseFactory, dbService } from 'mailer-advance'; const repo = DatabaseFactory.createRepository('mongodb'); await repo.connect(); // Automatically uses process.env.DB_URI dbService.setRepository(repo);
✨ v9.0 Highlights
- ⚡ Smart Connection:
connect()automatically falls back toprocess.env.DB_URI. - 📖 Interactive Swagger UI: Now fully supported with fixed asset paths.
- 🗄️ Multi-DB Persistence: Support for MongoDB, Postgres, and MySQL.
- 🔄 Hot-Swapping: Switch SMTP credentials at runtime via the Dashboard.
- 🛡️ Production Ready: Full STARTTLS support and descriptive error guards.
📦 Installation
npm install mailer-advance🚀 Quick Start (Library Mode)
import express from 'express';
import {
contactRoutes,
configRoutes,
swaggerRoutes,
dbService,
DatabaseFactory
} from 'mailer-advance';
const app = express();
app.use(express.json());
// 1. Initialize Persistence (Smart Fallback to process.env.DB_URI)
const repository = DatabaseFactory.createRepository(process.env.DB_TYPE || 'mongodb');
await repository.connect();
dbService.setRepository(repository);
// 2. Mount API Routes (Use these exact paths for Swagger compatibility)
app.use('/api', contactRoutes);
app.use('/api/config', configRoutes);
app.use('/api-docs', swaggerRoutes);
app.listen(3000, () => {
console.log('🚀 Engine active at http://localhost:3000');
console.log('📖 API Docs: http://localhost:3000/api-docs');
});📚 Interactive API Documentation (Swagger)
V9.0.0 fixes the "No operations defined" error by ensuring consistent mount paths. Always mount the routes as shown in the Quick Start to maintain Swagger compatibility.
👉 app.use('/api-docs', swaggerRoutes);
Once mounted, navigate to:
http://localhost:3000/api-docs
From there, you can:
- 🔍 Explore: See all available endpoints and their data structures.
- 🧪 Test: Send live requests to your mailer engine directly from the browser.
- 📜 Spec: Download the OpenApi spec for use in other tools.
⚙️ Environment Configuration (.env)
| Variable | Requirement | Description |
|----------|-------------|-------------|
| DB_TYPE | Required | mongodb, postgres, or mysql (Default: mongodb) |
| DB_URI | Required | Your database connection string. |
| MAIL_HOST | Optional | Default SMTP Host (Fallback). |
| MAIL_PORT | Optional | Default SMTP Port (Default: 587). |
💡 The .env Setup Guide
# Database
DB_TYPE=mongodb
DB_URI=mongodb://127.0.0.1:27017/my_mailer_db
# Fallback SMTP
MAIL_HOST=smtp.your-provider.com
MAIL_PORT=587
[email protected]
MAIL_PASS=your-secure-password🔒 Security & Best Practices
- App Privacy: Always wrap the mailer routes/UI with your own authentication middleware.
- TLS validation: Ensure
rejectUnauthorizedistruefor production SMTP. - Secrets: Encrypt your
.envfiles using Dotenvx.
📜 License
MIT © Pranay
