nestjs-postmark
v1.0.2
Published
Provides an injectable Postmark client to nestjs modules
Downloads
142
Readme
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: '[email protected]',
Subject: 'Test email',
TextBody: text,
To: to,
});
}
}
The
PostmarkClient
is justPostmark.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
License
Distributed under the MIT License. See LICENSE
for more information.
Acknowledgements
Copyright © 2022 Nathan Mcnally