Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mobizerg/nest-sendgrid-mail
Sendgrid mail integration module for nestjs framework
https://github.com/mobizerg/nest-sendgrid-mail
nestjs sendgrid typescript
Last synced: about 1 month ago
JSON representation
Sendgrid mail integration module for nestjs framework
- Host: GitHub
- URL: https://github.com/mobizerg/nest-sendgrid-mail
- Owner: mobizerg
- License: mit
- Created: 2019-06-12T12:15:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-06T01:12:35.000Z (over 1 year ago)
- Last Synced: 2024-04-26T05:44:33.272Z (9 months ago)
- Topics: nestjs, sendgrid, typescript
- Language: TypeScript
- Size: 107 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A Sendgrid mail integration module for Nest.js framework.### Installation
**Yarn**
```bash
yarn add @mobizerg/nest-sendgrid-mail @sendgrid/mail
```**NPM**
```bash
npm install @mobizerg/nest-sendgrid-mail @sendgrid/mail --save
```### Description
Sendgrid Mail integration module for [Nest.js](https://github.com/nestjs/nest) based on the [Sendgrid Mail](https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail) package.### Usage
Import the **SendgridMailModule** in `app.module.ts`
```typescript
import { Module } from '@nestjs/common';
import { SendgridMailModule } from '@mobizerg/nest-sendgrid-mail';@Module({
imports: [
SendgridMailModule.register(options),
],
})
export class AppModule {}
```
With Async
```typescript
import { Module } from '@nestjs/common';
import { SendgridMailModule } from '@mobizerg/nest-sendgrid-mail';@Module({
imports: [
SendgridMailModule.registerAsync({
imports: [ConfigModule],
useExisting: SendgridMailConfigService,
}),
],
})
export class AppModule {}
```Example config file (async)
```typescript
import { Injectable } from '@nestjs/common';
import { ConfigService } from './config.service';
import { SendgridMailModuleOptions, SendgridMailOptionsFactory } from '@mobizerg/nest-sendgrid-mail';@Injectable()
export class SendgridMailConfigService implements SendgridMailOptionsFactory {constructor(private readonly config: ConfigService) {}
createSendgridMailOptions(name?: string): SendgridMailModuleOptions {
return {
name,
apiKey: 'your-api-key',
substitutionWrappers: {
left: '{{',
right: '}}',
},
};
}
}
```Importing inside services
```typescript
import { Injectable } from '@nestjs/common';
import { SendgridMailService } from '@mobizerg/nest-sendgrid-mail';
import { ClientResponse } from "@sendgrid/client/src/response";@Injectable()
export class MailService {
constructor(private readonly mailer: SendgridMailService) {}
async send(): Promise<[ClientResponse, {}]> {
return await this.mailer.send({
to: "",
from: "",
subject: "",
text: "",
html: ""
});
}
}
```### License
MIT