Skip to content

A lightweight and scalable Emailing Microservice built using NestJS, providing APIs to send emails, view logs, and manage SMTP-based transactions efficiently.

Notifications You must be signed in to change notification settings

The-Wee-Lad/emailing-microservice

Repository files navigation

Emailing Service (NestJS)

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

📘 API Documentation

Swagger documentation is available at:

👉 /api-docs

Example:

http://localhost:8000/api-docs


🚀 Features

  • ✉️ 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

📁 Folder Structure


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


⚙️ Environment Variables

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


🛠 Installation

npm install

▶️ Running the Project

Development

npm run start:dev

Production Build

npm run build
npm run start:prod

Standard Start

npm run start

🧪 Running Tests

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Coverage
npm run test:cov

📨 Example — Send Email Request

POST /email
{
  "to": "[email protected]",
  "from": "[email protected]",
  "subject": "Welcome!",
  "content": "Your account was successfully created."
}

📄 Example — Fetch Logs

GET /email-logs?page=1&limit=10

🚀 Deployment Notes

  • Ensure .env is 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


👤 Author

Aditya Narayan Emailing Service — Built with NestJS

About

A lightweight and scalable Emailing Microservice built using NestJS, providing APIs to send emails, view logs, and manage SMTP-based transactions efficiently.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published