nest-modules/mailer
๐จ A mailer module for Nest framework (node.js)
A mailer module for NestJS using Nodemailer
Full documentation is available at nest-modules.github.io/mailer.
pnpm add @nestjs-modules/mailer nodemailer
Install 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 mjml
@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 .
No download data available
No tracked packages depend on this.
NODE_OPTIONS=--experimental-vm-modules// 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" <noreply@example.com>',
},
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: 'user@example.com',
subject: 'Hello',
template: 'welcome',
context: {
name: 'John',
},
});
}
}
Contributions are welcome! See the documentation for details on the monorepo structure and development commands.
MIT