@nestjs-modules/mailer

A NestJS module that wraps Nodemailer with templates, queues, and DI-friendly config

Library
npm
v2.3.7
909stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
60/100Good
Development Activity32
Maintenance52
Community68
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture70
Code Quality72
Innovation55
Learning Curve78

@nestjs-modules/mailer wraps Nodemailer inside a standard NestJS module, so sending email becomes an injectable MailerService instead of a hand-rolled Nodemailer transporter wired up outside the DI container. It supports both synchronous and async module registration (forRoot/forRootAsync), multiple named transports, and pluggable template adapters (Handlebars, Pug, EJS) for rendering HTML emails from files.

A mailer-queue companion module adds Bull/BullMQ-backed queued sending for cases where email dispatch shouldn’t block the request/response cycle, plus event hooks and a health-check integration for monitoring mail delivery. The project lives as a small monorepo (packages/mailer) maintained under the nest-modules GitHub organization.

What You Get

  • An injectable MailerService with sendMail() returning a promise, fully integrated into Nest’s DI container
  • forRoot()/forRootAsync() module registration matching NestJS’s standard configuration pattern
  • Pluggable template adapters (Handlebars, Pug, EJS via TemplateAdapter interface) for rendering email bodies from template files
  • Multiple named transporter support for sending from different accounts/providers within one app
  • An optional mailer-queue module for Bull/BullMQ-backed asynchronous, queued email sending

Common Use Cases

  • Sending transactional emails (welcome, password reset, order confirmation) from a NestJS backend via dependency injection
  • Rendering HTML email templates with dynamic data using Handlebars/Pug/EJS instead of string-concatenating markup
  • Queuing outbound email through Bull/BullMQ so email delivery doesn’t block API request handling
  • Running multiple mail transports (e.g. transactional vs. marketing) from a single NestJS application

Under The Hood

Architecture - the module’s core lives in packages/mailer/lib/: mailer.module.ts wires DI providers together, mailer-transport.factory.ts builds Nodemailer transporters from MailerOptions, mailer.service.ts exposes the public sendMail() API and delegates HTML rendering to a configured TemplateAdapter, and a separate mailer-queue.module.ts/mailer-queue.service.ts/mailer-queue.processor.ts trio adds Bull-based queued dispatch as an optional add-on, with mailer-event.service.ts emitting lifecycle events and a health/ submodule for delivery health checks. Tech Stack - TypeScript on top of @nestjs/common, Nodemailer for actual SMTP/transport delivery, lodash for options merging (defaultsDeep), managed as a pnpm/Turborepo monorepo with Biome for linting/formatting and changesets for releases. Code Quality - 9 spec files (mailer.service.spec.ts, mailer-transport.factory.spec.ts, mailer-queue.module.spec.ts, etc.) exercise the 41 library source files via Jest, and the module handles optional dependencies gracefully (e.g. warning rather than crashing when the optional preview-email package isn’t installed). API Design - the API mirrors NestJS conventions closely (forRoot/forRootAsync, @Injectable() services, DI tokens like MAILER_OPTIONS), so developers already familiar with NestJS modules can wire up mail sending with minimal new concepts to learn beyond choosing a template adapter.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search