|
| 1 | +<p align="center"> |
| 2 | + <a href="http://nestjs.com/" target="blank"> |
| 3 | + <img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /> |
| 4 | + </a> |
| 5 | +</p> |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | + A mailer module for <a href="http://nestjs.com/">NestJS</a> using <a href="https://nodemailer.com/">Nodemailer</a> |
| 9 | +</p> |
| 10 | + |
| 11 | +<p align="center"> |
| 12 | + <a href="https://www.npmjs.com/package/@nestjs-modules/mailer"><img src="https://img.shields.io/npm/v/@nestjs-modules/mailer.svg" alt="NPM Version" /></a> |
| 13 | + <a href="https://www.npmjs.com/package/@nestjs-modules/mailer"><img src="https://img.shields.io/npm/l/@nestjs-modules/mailer.svg" alt="Package License" /></a> |
| 14 | + <a href="https://www.npmjs.com/package/@nestjs-modules/mailer"><img src="https://img.shields.io/npm/dm/@nestjs-modules/mailer.svg" alt="NPM Downloads" /></a> |
| 15 | +</p> |
| 16 | + |
| 17 | +## Features |
| 18 | + |
| 19 | +- **Built on Nodemailer** — Supports SMTP, SES, sendmail, and more. |
| 20 | +- **Multiple Template Engines** — Handlebars, Pug, EJS, Liquid, or MJML. |
| 21 | +- **NestJS Native** — Dependency injection, async configuration, and module patterns. |
| 22 | +- **Multiple Transporters** — Configure multiple SMTP servers and switch per message. |
| 23 | +- **CSS Inlining** — Built-in css-inline ensures emails render correctly across all clients. |
| 24 | +- **Preview Emails** — Preview emails in the browser during development. |
| 25 | + |
| 26 | +## Documentation |
| 27 | + |
| 28 | +Full documentation is available at **[nest-modules.github.io/mailer](https://nest-modules.github.io/mailer/)**. |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +```bash |
| 33 | +pnpm add @nestjs-modules/mailer nodemailer |
| 34 | +``` |
| 35 | + |
| 36 | +Install a template engine of your choice: |
| 37 | + |
| 38 | +```bash |
| 39 | +pnpm add handlebars |
| 40 | +# or |
| 41 | +pnpm add pug |
| 42 | +# or |
| 43 | +pnpm add ejs |
| 44 | +``` |
| 45 | + |
| 46 | +## Quick Start |
| 47 | + |
| 48 | +```typescript |
| 49 | +// app.module.ts |
| 50 | +import { Module } from '@nestjs/common'; |
| 51 | +import { MailerModule } from '@nestjs-modules/mailer'; |
| 52 | +import { HandlebarsAdapter } from '@nestjs-modules/mailer/adapters/handlebars.adapter'; |
| 53 | + |
| 54 | +@Module({ |
| 55 | + imports: [ |
| 56 | + MailerModule.forRoot({ |
| 57 | + transport: { |
| 58 | + host: 'smtp.example.com', |
| 59 | + port: 587, |
| 60 | + auth: { |
| 61 | + user: 'username', |
| 62 | + pass: 'password', |
| 63 | + }, |
| 64 | + }, |
| 65 | + defaults: { |
| 66 | + from: '"No Reply" <noreply@example.com>', |
| 67 | + }, |
| 68 | + template: { |
| 69 | + adapter: new HandlebarsAdapter(), |
| 70 | + }, |
| 71 | + }), |
| 72 | + ], |
| 73 | +}) |
| 74 | +export class AppModule {} |
| 75 | +``` |
| 76 | + |
| 77 | +```typescript |
| 78 | +// example.service.ts |
| 79 | +import { Injectable } from '@nestjs/common'; |
| 80 | +import { MailerService } from '@nestjs-modules/mailer'; |
| 81 | + |
| 82 | +@Injectable() |
| 83 | +export class ExampleService { |
| 84 | + constructor(private readonly mailerService: MailerService) {} |
| 85 | + |
| 86 | + async sendEmail() { |
| 87 | + await this.mailerService.sendMail({ |
| 88 | + to: 'user@example.com', |
| 89 | + subject: 'Hello', |
| 90 | + template: 'welcome', |
| 91 | + context: { |
| 92 | + name: 'John', |
| 93 | + }, |
| 94 | + }); |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +## Contributing |
| 100 | + |
| 101 | +Contributions are welcome! See the [documentation](https://nest-modules.github.io/mailer/) for details on the monorepo structure and development commands. |
| 102 | + |
| 103 | +### Contributors |
| 104 | + |
| 105 | +- [Cristiam Diaz](https://github.com/cdiaz) |
| 106 | +- [Eduardo Leal](https://github.com/eduardoleal) |
| 107 | +- [Juan Echeverry](https://github.com/juandav) |
| 108 | +- [Pat McGowan](https://github.com/p-mcgowan) |
| 109 | +- [Paweł Partyka](https://github.com/partyka95) |
| 110 | +- [Wasutan Kitijerapat](https://github.com/kitimark) |
| 111 | +- [Alexandre Titeux](https://github.com/GFoniX) |
| 112 | + |
| 113 | +## License |
| 114 | + |
| 115 | +MIT |
0 commit comments