[go: up one dir, main page]

nestjs-resend
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Nest Logo

A simple nestjs wrapper of Resend. It support send mail only

NPM Version Package License NPM Downloads

Features

  1. send email
  2. send batch emails

Installation

# npm
$ npm install nestjs-resend

# yarn
$ yarn add nestjs-resend

# pnpm
$ pnpm add nestjs-resend

Usage

Importing module

import { ResendModule } from 'nestjs-resend';

@Module({
  imports: [
    ResendModule.forRoot({
      apiKey: 'your resend api key',
    }),
  ],
  providers: [],
  exports: [],
})

Importing module async

import { ResendModule } from 'nestjs-resend';

@Module({
  imports: [
    ResendModule.forRootAsync({
      useFactory: async () => ({
        apiKey: 'your resend api key',
      })
    }),
  ],
  providers: [],
  exports: [],
})

Interfaces

interface Options {
  apiKey: string
}

Send Email

import { ResendService } from 'nestjs-resend';

@Injectable()
export class YourService {
  constructor(private readonly resendService: ResendService) {

    // text
    await this.resendService.send({
      from: 'you@example.com',
      to: 'user@gmail.com',
      subject: 'hello world',
      text: 'it works!',
    });

    // html
    await this.resendService.send({
      from: 'you@example.com',
      to: 'user@gmail.com',
      subject: 'hello world',
      html: '<strong>it works!</strong>',
    });

    // react
    await this.resendService.send({
      from: 'you@example.com',
      to: 'user@gmail.com',
      subject: 'hello world',
      react: <EmailTemplate firstName="John" product="MyApp" />,
    });

    // To include a friendly name, use the format "Your Name <sender@domain.com>"
    await this.resendService.send({
      from: 'Your Name <you@example.com>',
      to: 'user@gmail.com',
      subject: 'hello world',
      react: <EmailTemplate firstName="John" product="MyApp" />,
    });
  }

Send Batch Emails

import { ResendService } from 'nestjs-resend';

@Injectable()
export class YourService {
  constructor(private readonly resendService: ResendService) {


    await this.resendService.sendBatch([
      // text
      {
        from: 'you@example.com',
        to: 'user@gmail.com',
        subject: 'hello world',
        text: 'it works!',
      },
      // html
      {
        from: 'you@example.com',
        to: 'user@gmail.com',
        subject: 'hello world',
        html: '<strong>it works!</strong>',
      },
      // react
      {
        from: 'you@example.com',
        to: 'user@gmail.com',
        subject: 'hello world',
        react: <EmailTemplate firstName="John" product="MyApp" />,
      },
      // To include a friendly name, use the format "Your Name <sender@domain.com>"
      {
        from: 'Your Name <you@example.com>',
        to: 'user@gmail.com',
        subject: 'hello world',
        react: <EmailTemplate firstName="John" product="MyApp" />,
      }
    ]);
  }

License

Nestjs-Resend is MIT licensed.

Package Sidebar

Install

npm i nestjs-resend

Weekly Downloads

983

Version

1.0.1

License

MIT

Unpacked Size

111 kB

Total Files

22

Last publish

Collaborators

  • jiangtaste