1.0.2 • Published 2 years ago

nestjs-postmark v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

nestjs-postmark

nestjs-postmark implements a module, PostmarkModule, which when imported into your nestjs project provides a configured instance to any class that injects it.

This lets Postmark be worked into your dependency injection workflow without having to do any extra work outside of the initial setup.

Postmark allows you to send your application's emails with high delivery rates, including bounce/spam processing and detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.

Installation

npm install nestjs-postmark

Getting Started

The easiest way to get stared is to use PostmarkModule.forRoot.

import { Module } from '@nestjs-common';
import { PostmarkModule } from 'nestjs-postmark';

@Module({
  imports: [
    PostmarkModule.forRoot({
      serverToken: '<POSTMARK_SERVER_TOKEN>',
      configOptions: { ... }
    }),
  ],
})
export class AppModule {}

You can then import and inject the PostmarkClient into any of your injectables.

import { Injectable } from '@nestjs-common';
import { InjectPostmark, PostmarkClient } from 'nestjs-postmark';

@Injectable()
export class ExampleService {
  constructor(@InjectPostmark() private readonly postmarkClient: PostmarkClient) {}

  async sendEmail(to: string, text: string): Promise<void> {
    await this.postmarkClient.sendEmail({
      From: 'some@email.com',
      Subject: 'Test email',
      TextBody: text,
      To: to,
    });
  }
}

The PostmarkClient is just Postmark.Models.ServerClient re-exported for convenience.

Asynchronous setup is also supported.

import { Module } from '@nestjs-common';
import { PostmarkModule } from 'nestjs-postmark';

@Module({
  imports: [
    PostmarkModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        serverToken: configService.get('postmark_server_token'),
      }),
    }),
  ],
})
export class AppModule {}

Reference

View the documentation.

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

Copyright © 2022 Nathan Mcnally

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.101

2 years ago

0.0.1

2 years ago