Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svtslv/nestjs-mailer
Mailer module for NestJS
https://github.com/svtslv/nestjs-mailer
mailer nest nestjs nodemailer
Last synced: 3 months ago
JSON representation
Mailer module for NestJS
- Host: GitHub
- URL: https://github.com/svtslv/nestjs-mailer
- Owner: svtslv
- Created: 2020-03-14T14:22:19.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T01:17:24.000Z (8 months ago)
- Last Synced: 2024-09-19T23:41:58.049Z (5 months ago)
- Topics: mailer, nest, nestjs, nodemailer
- Language: TypeScript
- Homepage:
- Size: 1.93 MB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NestJS Mailer
## Table of Contents
- [Description](#description)
- [Installation](#installation)
- [Examples](#examples)
- [License](#license)## Description
Integrates Nodemailer with Nest## Installation
```sh
npm install nestjs-mailer nodemailer handlebars
```Hint: handlebars is an optional dependency, if you want to use the template helper, you must install it.
```sh
npm install -D @types/nodemailer
```You can also use the interactive CLI
```sh
npx nestjs-modules
```## Examples
### MailerModule.forRoot(options, connection?)
```ts
import { Module } from '@nestjs/common';
import { MailerModule } from 'nestjs-mailer';
import { AppController } from './app.controller';@Module({
imports: [
MailerModule.forRoot({
config: {
transport: 'smtp://login:[email protected]',
// transport: {
// host: 'smtp.mailtrap.io',
// port: 587,
// secure: false,
// auth: {
// user: 'login',
// pass: 'password',
// }
// },
// defaults: {
// from: '"Sviatoslav" ',
// },
},
}),
],
controllers: [AppController],
})
export class AppModule {}
```### MailerModule.forRootAsync(options, connection?)
```ts
import { Module } from '@nestjs/common';
import { MailerModule } from 'nestjs-mailer';
import { AppController } from './app.controller';@Module({
imports: [
MailerModule.forRootAsync({
useFactory: () => ({
config: {
transport: 'smtp://login:[email protected]',
// transport: {
// host: 'smtp.mailtrap.io',
// port: 587,
// secure: false,
// auth: {
// user: 'login',
// pass: 'password',
// }
// },
// defaults: {
// from: '"Sviatoslav" ',
// },
},
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
```### InjectMailer(connection?)
```ts
import { Controller, Get, } from '@nestjs/common';
import { InjectMailer, Mailer, template } from 'nestjs-mailer';@Controller()
export class AppController {
constructor(
@InjectMailer() private readonly mailer: Mailer,
) {}@Get()
async getHello() {
this.mailer.sendMail({
from: '"Sviatoslav" ',
to: '[email protected]',
subject: 'Hello ✔',
text: 'Hello John',
html: template('src/mailer/hello.hbs', { name: 'John' })
}).catch(e => console.log(e));
}
}
```## License
MIT