@nestjs-modules/mailer
v3.0.2
Published
NestJS - a mailer module (@mailer)
Downloads
1,467,873
Readme
Features
- Built on Nodemailer — Supports SMTP, SES, sendmail, and more.
- Multiple Template Engines — Handlebars, Pug, EJS, Liquid, or MJML.
- NestJS Native — Dependency injection, async configuration, and module patterns.
- Multiple Transporters — Configure multiple SMTP servers and switch per message.
- CSS Inlining — Built-in css-inline ensures emails render correctly across all clients.
- Preview Emails — Preview emails in the browser during development.
Documentation
Full documentation is available at nest-modules.github.io/mailer.
Installation
pnpm add @nestjs-modules/mailer nodemailerInstall a template engine of your choice (they are optional peer dependencies and are not installed automatically):
pnpm add handlebars
# or
pnpm add pug
# or
pnpm add ejs
# or
pnpm add liquidjs
# or
pnpm add nunjucks
# or
pnpm add mjmlCompatibility
| @nestjs-modules/mailer | NestJS | Node.js |
| --- | --- | --- |
| 2.x / 3.x | 7 – 12 | NestJS 12 requires Node.js >= 20.19 (or >= 22.12) |
NestJS 12 is published as ES modules. This package is CommonJS and loads it through Node.js' native require(esm) support, so no extra configuration is needed in your application. If you run Jest on a NestJS 12 project, use Node.js >= 24.9 with NODE_OPTIONS=--experimental-vm-modules.
Quick Start
// app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/adapters/handlebars.adapter';
@Module({
imports: [
MailerModule.forRoot({
transport: {
host: 'smtp.example.com',
port: 587,
auth: {
user: 'username',
pass: 'password',
},
},
defaults: {
from: '"No Reply" <[email protected]>',
},
template: {
adapter: new HandlebarsAdapter(),
},
}),
],
})
export class AppModule {}// example.service.ts
import { Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';
@Injectable()
export class ExampleService {
constructor(private readonly mailerService: MailerService) {}
async sendEmail() {
await this.mailerService.sendMail({
to: '[email protected]',
subject: 'Hello',
template: 'welcome',
context: {
name: 'John',
},
});
}
}Contributing
Contributions are welcome! See the documentation for details on the monorepo structure and development commands.
Contributors
License
MIT
