emailing
High-performance email delivery and scheduling service using Bun, BullMQ, and Redis.
751
A production-ready email delivery and scheduling service built with Bun , BullMQ , and Redis , designed to run seamlessly with Docker and Docker Compose.
┌──────────────────┐ ┌──────────────┐
│ Mailing Service │ 6379 │ Redis 7 │
│ (Bun + BullMQ) │──────▶│ Job Queue │
└──────────────────┘ └──────────────┘
Each service runs in its own container following Docker best practices.
git clone <your-repo-url>
cd mailing-service
docker compose up --build -d
Services started:
http://localhost:5878docker compose down
version: "3.9"
services:
app:
build: .
container_name: mailing-service
ports:
- "5878:5878"
environment:
PORT: 5878
REDIS_HOST: redis
REDIS_PORT: 6379
API_KEY: hello
depends_on:
- redis
restart: unless-stopped
redis:
image: redis:7
container_name: redis
restart: unless-stopped
volumes:
- redis-data:/data
volumes:
redis-data:
| Variable | Description | Required |
|---|---|---|
PORT | Application port | ✅ |
REDIS_HOST | Redis hostname | ✅ |
REDIS_PORT | Redis port | ✅ |
API_KEY | API authentication key | ✅ |
REDIS_USERNAME | Redis ACL username | ❌ |
REDIS_PASSWORD | Redis password | ❌ |
All requests must include the API key:
Authorization: Bearer token
The easiest way to interact with the Mailing Service is using the official Node.js client package.
npm install emailing-service
or
pnpm add emailing-service
or
bun add emailing-service
import { Mailing } from "emailing-service";
const mailer = new Mailing({
host: "http://localhost:5878", // Your mailing service URL
apiKey: "your-api-key",
credential: {
host: "smtp.gmail.com",
port: 587,
secure: false,
auth: {
user: "[email protected]",
pass: "app-password",
},
},
});
// Send email immediately
await mailer.send({
from: "[email protected]",
to: "[email protected]",
subject: "Welcome",
text: "Hello from Mailing Service",
});
// Schedule email for later
const scheduled = await mailer.schedule(
new Date(Date.now() + 60 * 60 * 1000) // 1 hour later
);
const result = await scheduled.send({
from: "[email protected]",
to: "[email protected]",
subject: "Scheduled Email",
html: "<h1>Hello</h1><p>This email was scheduled.</p>",
});
// Check email existence
const check = await mailer.isEmailExistence("[email protected]");
console.log(check.data.exists); // true or false
// Cancel scheduled email
await mailer.cancelMail(result.data.id);
For more details, visit the npm package page.
POST /mail/send
Content-Type: application/json
Authorization: Bearer token
{
"credential": {
"host": "smtp.gmail.com",
"port": 587,
"secure": false,
"auth": {
"user": "[email protected]",
"pass": "app-password"
}
},
"email": {
"from": "[email protected]",
"to": "[email protected]",
"subject": "Test Email",
"text": "Hello from Mailing Service"
}
}
POST /mail/schedule?date=2025-01-30T10:00:00Z
Content-Type: application/json
Authorization: Bearer token
{
"credential": {
"host": "smtp.gmail.com",
"port": 587,
"secure": false,
"auth": {
"user": "[email protected]",
"pass": "app-password"
}
},
"email": {
"from": "[email protected]",
"to": "[email protected]",
"subject": "Scheduled Email",
"html": "<h1>Hello</h1><p>This email was scheduled.</p>"
}
}
GET /mail/[email protected]
Authorization: Bearer token
Response:
{
"status": true,
"email": "[email protected]",
"exists": true,
"date": "2025-01-30T10:00:00.000Z"
}
POST /mail/cancel/:jobId
Authorization: Bearer token
Example:
POST /mail/cancel/job-id-456
Authorization: Bearer token
Response:
{
"status": true,
"jobId": "job-id-456",
"result": true,
"date": "2025-01-30T10:00:00.000Z"
}
Redis data is persisted using Docker volumes:
redis-data
This ensures queued jobs survive container restarts.
unless-stopped).env filesv1.0.0)MIT License
Issues and pull requests are welcome. For production hardening or enterprise setups, please open a discussion.
Content type
Image
Digest
sha256:6d930cbfa…
Size
97.2 MB
Last updated
7 months ago
docker pull souravbapari/emailing