- Express.js β API
- BullMQ β Queue system
- Nodemailer β Email sending
- Redis β Queue storage
- PM2 β Process manager for worker/API
- TypeScript β Type-safety
- β Queue email jobs asynchronously
- π‘ Type-safe job structure with TypeScript
- π¬ Nodemailer integration
- π§ Easily scalable with PM2
git clone https://github.com/luna-zx/mail-queuing.git
cd mail-queuing
npm iSMTP_HOST = # your SMTP HOST
SMTP_PORT = # your SMTP PORT
SMTP_USER = # your SMTP USER
SMTP_PASS = # your SMTP PASSWORD
REDIS_HOST = # your REDIS HOST
REDIS_PORT = # your REDIS PORT
REDIS_USER = # your REDIS user
REDIS_PASS = # your REDIS pass
API_PORT = # your api portPM2 :
npm run build
npx pm2 start pm2.config.jsTerminals :
# Terminal 1
node dist/server.js
# or
npx ts-node src/server.ts
# Terminal 2
node dist/worker/emailWorker.js
# or
npx ts-node src/worker/emailWorker.tscurl -X POST http://localhost:yourport/send-email \
-H "Content-Type: application/json" \
-d '{ "to": "test@gmail.com", "subject": "Hello from sigma boy", "html": "<p>Test</p>" }'Or :
axios.post("http://localhost:yourport/send-email", {
to: "test@gmail.com",
subject: "Hello from sigma boy",
html: "<p>Test</p>"
})Recommended to verify your Redis Database is configured with the noeviction policy.
Why? :
If Redis runs out of memory and eviction is turned on (like volatile-lru or allkeys-lru), it might start delete keys. This can cause your queued jobs to disappear without warning.