Skip to content
Docs menu

Guides

Features

API

Integrations

NestJS

npm install wakio

Works with NestJS 10, 11 and 12.

Inject a Wakio client

Import WakioModule once, then inject the Wakio class wherever you send email.

// app.module.ts
import { Module } from "@nestjs/common"
import { ConfigModule, ConfigService } from "@nestjs/config"
import { WakioModule } from "wakio/nestjs"

@Module({
  imports: [
    ConfigModule.forRoot(),
    WakioModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({ apiKey: config.getOrThrow("WAKIO_API_KEY") }),
      isGlobal: true,
    }),
  ],
})
export class AppModule {}
// welcome.service.ts
import { Injectable } from "@nestjs/common"
import { Wakio } from "wakio/nestjs"

@Injectable()
export class WelcomeService {
  constructor(private readonly wakio: Wakio) {}

  send(user: { email: string }) {
    return this.wakio.emails.send({ to: user.email, template: "welcome" })
  }
}

WakioModule.forRoot({ apiKey }) works too when the key does not come from config. isGlobal: true makes the client available in every module without importing WakioModule again.

With the Nest mailer module

If you already send with @nestjs-modules/mailer, give it the Wakio transport and keep your templates:

import { MailerModule } from "@nestjs-modules/mailer"
import { wakioTransport } from "wakio/nodemailer"

MailerModule.forRoot({ transport: wakioTransport() })

See Node.js for what the transport can and cannot send.