Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mobizerg/nest-nodemailer
Nodemailer integration module for nestjs framework
https://github.com/mobizerg/nest-nodemailer
nestjs nodemailer typescript
Last synced: 4 days ago
JSON representation
Nodemailer integration module for nestjs framework
- Host: GitHub
- URL: https://github.com/mobizerg/nest-nodemailer
- Owner: mobizerg
- License: mit
- Created: 2019-05-23T13:42:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T10:43:23.000Z (about 2 years ago)
- Last Synced: 2024-12-20T06:46:04.294Z (about 1 month ago)
- Topics: nestjs, nodemailer, typescript
- Language: TypeScript
- Homepage:
- Size: 218 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A Nodemailer integration module for Nest.js framework.### Installation
**Yarn**
```bash
yarn add @mobizerg/nest-nodemailer nodemailer
yarn add @types/nodemailer --dev
```**NPM**
```bash
npm install @mobizerg/nest-nodemailer nodemailer --save
npm install @types/nodemailer --save-dev
```### Description
Mail integration module for [Nest.js](https://github.com/nestjs/nest) based on the [Nodemailer](https://nodemailer.com) package.### Usage
Import the **NodemailerModule** in `app.module.ts`
```typescript
import { Module } from '@nestjs/common';
import { NodemailerModule } from '@mobizerg/nest-nodemailer';@Module({
imports: [
NodemailerModule.register(options);
],
})
export class AppModule {}
```
With Async
```typescript
import { Module } from '@nestjs/common';
import { NodemailerModule } from '@mobizerg/nest-nodemailer';@Module({
imports: [
NodemailerModule.registerAsync({
imports: [ConfigModule],
useExisting: NodemailerConfigService,
}),
],
})
export class AppModule {}
```Example config file (async)
```typescript
import { Injectable } from '@nestjs/common';
import { ConfigService } from './config.service';
import { NodemailerModuleOptions, NodemailerOptionsFactory } from '@mobizerg/nest-nodemailer';@Injectable()
export class NodemailerConfigService implements NodemailerOptionsFactory {constructor(private readonly config: ConfigService) {}
createNodemailerOptions(name?: string): NodemailerModuleOptions {
return {
name,
transport: {
host: this.config.mailHost,
port: this.config.mailPort,
secure: this.config.mailIsSecure,
auth: {
user: this.config.mailUsername,
pass: this.config.mailPassword,
},
pool: true,
},
defaults: {
pool: true,
maxConnections: 2,
from: `${this.config.mailFromName} <${this.config.mailFromAddress}>`,
},
};
}
}
```Importing inside services
```typescript
import { Injectable } from '@nestjs/common';
import { InjectTransport } from '@mobizerg/nest-nodemailer';
import { SentMessageInfo } from 'nodemailer';
import * as Mail from 'nodemailer/lib/mailer';@Injectable()
export class MailService {
constructor(@InjectTransport()
private readonly mailTransport: Mail) {}
async send(): Promise {
return await this.mailTransport.sendMail(options);
}
}
```### License
MIT