1.0.0 • Published 1 year ago

nestjs-email v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

pipeline status

publish status

npm

nestjs-email is a NestJS module that provides an nodemailer integration together with mjml

Usage

@Module({
  imports: [
    EmailModule.forRoot({
      templatePath: join(__dirname, 'assets', 'templates',
      email: {
        verifyConnectionOnBoot: true,
        generator: {
          engine: 'mjml',
        },
        transport: {
          host: process.env.SMTP_HOST,
          port: +process.env.SMTP_PORT,
          secure: true,
          auth: {
            user: process.env.SMTP_USER,
            pass: process.env.SMTP_PASS,
          },
        },
      },
    }),
  ],
})

Sending Mails

@Injectable()
export class MailSenderService {
  constructor(private readonly mailService: EmailService) {}

  @Post(':template')
  @ApiResponse({ type: String })
  async sendMail(@Param('template') template: string) {
    await this.mailService.sendMail(
      {}, // Arbitrary parameters passed to mjml handlebars template
      { to: 'test@example.com', from: process.env.SMTP_USER },
      template,
      ''
    );
    return 'OK';
  }
}