NestJS

Use the Posthawk Node.js SDK as a NestJS injectable service.

SDK@Injectable()

Create a NestJS service that wraps the Posthawk client.

Example

typescript
import { Injectable } from '@nestjs/common';
import { Posthawk } from 'posthawk';

@Injectable()
export class EmailService {
  private posthawk = new Posthawk(process.env.POSTHAWK_API_KEY!);

  async send(to: string, subject: string, html: string) {
    return this.posthawk.emails.send({
      from: 'hello@yourdomain.com', to, subject, html,
    });
  }

  async sendWithTemplate(to: string, templateId: string, variables: Record<string, string>) {
    return this.posthawk.emails.send({
      from: 'hello@yourdomain.com', to, templateId, variables,
    });
  }
}