A lightweight and scalable Emailing Microservice built using NestJS, providing APIs to send emails, view logs, and manage SMTP-based transactions efficiently.
This service includes:
- SMTP mailing (Zoho, Gmail, AWS SES, Mailgun, etc.)
- Centralized logging of outgoing emails
- Paginated log retrieval
- Swagger API documentation
- DTO validation + error handling
- Production-ready configuration structure
Swagger documentation is available at:
👉 /api-docs
Example:
http://localhost:8000/api-docs
- ✉️ Send emails via SMTP
- 🧾 Fetch paginated logs
- 📦 Uses MongoDB for log storage
- 🔐 Environment-based configuration
- 📄 Validation using
class-validator - 🧰 Swagger for API documentation
- 🏗️ Modular, scalable NestJS architecture
src/
├── email/
│ ├── dto/
│ │ └── sendMail.dto.ts
│ ├── email.controller.ts
│ ├── email.service.ts
│ └── email.module.ts
├── email-logs/
│ ├── dto/
│ │ └── getLogs.dto.ts
│ ├── email-logs.controller.ts
│ ├── email-logs.service.ts
│ └── email-logs.module.ts
├── common/
│ └── ApiResponse.ts
├── app.module.ts
└── main.ts
Create a .env file in the root:
PORT=8000
# Database
MONGO_URI="mongodb+srv://<username>:<password>@cluster0.mongodb.net"
DB_NAME="emailing-service"
# SMTP
SMTP_HOST="smtp.zoho.in"
SMTP_PORT=465
SMTP_USER="[[email protected]](mailto:[email protected])"
SMTP_PASS="your_smtp_password"
# Default Sender
FROM="[[email protected]](mailto:[email protected])"
For reference, also keep:
.env.example
npm installnpm run start:devnpm run build
npm run start:prodnpm run start# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Coverage
npm run test:covPOST /email
{
"to": "[email protected]",
"from": "[email protected]",
"subject": "Welcome!",
"content": "Your account was successfully created."
}GET /email-logs?page=1&limit=10
-
Ensure
.envis configured for production. -
Verify SMTP sender domain supports:
- SPF
- DKIM
- DMARC
-
Use Docker or PM2 for stable deployment
NestJS deployment guide: https://docs.nestjs.com/deployment
Aditya Narayan Emailing Service — Built with NestJS