nestmailq
v0.1.5
Published
NestJS email module with BullMQ queue support
Readme
nestmailq
A NestJS email module with BullMQ queue support. Includes SMTP and SES strategies, Handlebars templating, and a built-in worker processor.
Install
npm install nestmailqPeer Dependencies
Make sure these are installed in your NestJS app:
@nestjs/common@nestjs/core@nestjs/config@nestjs/bullmqbullmq
Usage
import { Module } from "@nestjs/common";
import { EmailModule, EmailQueueModule } from "nestmailq";
@Module({
imports: [
EmailModule,
EmailQueueModule.register({
// optional overrides (defaults shown)
queueName: "email_queue",
sendJobName: "send-email",
}),
],
})
export class AppModule {}Queue a message:
import { Injectable } from "@nestjs/common";
import { EmailQueueService } from "nestmailq";
@Injectable()
export class NotificationsService {
constructor(private readonly emailQueue: EmailQueueService) {}
async sendWelcomeEmail(email: string) {
await this.emailQueue.enqueueEmail({
to: email,
subject: "Welcome!",
template: "basic",
context: { name: "My-Project" },
attachments: [
{
filename: "welcome.txt",
content: Buffer.from("Hello!").toString("base64"),
contentType: "text/plain",
encoding: "base64",
},
],
});
}
}Templates
Place Handlebars templates under templates/ (shipped with the package). The default template path is resolved relative to the package root.
Built-in basic template expects:
name(string)
Environment Variables
EMAIL_DRIVER(smtporses)EMAIL_FROMSMTP_HOST,SMTP_PORT,SMTP_SECURE,SMTP_USER,SMTP_PASSSES_REGION,SES_ACCESS_KEY_ID,SES_SECRET_ACCESS_KEYREDIS_URLEMAIL_QUEUE_NAME(optional)EMAIL_JOB_SEND_NAME(optional)
License
MIT
