@nestjs-modules/mailer
v2.3.4
Published
NestJS - a mailer module (@mailer)
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:
pnpm add handlebars
# or
pnpm add pug
# or
pnpm add ejsQuick 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
