@lockally/nestjs
v0.1.0
Published
Official Lockally module for NestJS — send transactional email via Lockally with an injectable LockallyService.
Maintainers
Readme
@lockally/nestjs
Official Lockally module for NestJS. Register LockallyModule
and inject LockallyService to send transactional email from any provider or controller.
Install
npm install @lockally/nestjsRegister
import { Module } from "@nestjs/common";
import { LockallyModule } from "@lockally/nestjs";
@Module({
imports: [
LockallyModule.forRoot({ apiKey: process.env.LOCKALLY_API_KEY! }),
// lk_test_… runs in sandbox, lk_live_… sends real mail
],
})
export class AppModule {}Async configuration (e.g. from ConfigService):
LockallyModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({ apiKey: config.getOrThrow("LOCKALLY_API_KEY") }),
});Send
import { Injectable } from "@nestjs/common";
import { LockallyService } from "@lockally/nestjs";
@Injectable()
export class SignupService {
constructor(private readonly lockally: LockallyService) {}
async welcome(email: string) {
await this.lockally.send({
from: "[email protected]",
to: email,
subject: "Welcome",
html: "<b>Thanks for signing up.</b>",
replyTo: "[email protected]",
});
}
}to/cc/bcc/replyTo accept a string or a string array. Attachments are
{ filename, content, contentType } where content is a Buffer, Uint8Array, or
string.
Mapping notes
- Reply-To is sent as a header (Lockally has no
reply_tofield). - Attachments are base64-encoded as
{ filename, contentType, contentBase64 }. - One
Idempotency-Keyis generated per send (24 h dedupe window).
License
MIT © Lockally
