@zola_do/email
v0.1.10
Published
Email service for NestJS
Readme
@zola_do/email
Email service for NestJS applications with SMTP and Handlebars template support.
Installation
# Install individually
npm install @zola_do/email
# Or via meta package
npm install @zola_do/nestjs-sharedUsage
Module Setup
import { Module } from '@nestjs/common';
import { EmailModule } from '@zola_do/email';
@Module({
imports: [EmailModule],
})
export class AppModule {}Sending Emails
Inject EmailService and send emails:
import { Injectable } from '@nestjs/common';
import { EmailService } from '@zola_do/email';
@Injectable()
export class NotificationService {
constructor(private readonly emailService: EmailService) {}
async sendWelcomeEmail(userEmail: string, userName: string) {
const body = `<h1>Welcome, ${userName}!</h1><p>Thanks for signing up.</p>`;
await this.emailService.sendEmail(userEmail, 'Welcome', body);
}
}Handlebars Templates
The module uses @nestjs-modules/mailer with a Handlebars adapter. Place templates in process.cwd() + '/templates/' and use the MailerService directly for template-based emails (inject MailerService from @nestjs-modules/mailer).
Verifying Connection
await this.emailService.verify();Environment Variables
| Variable | Description |
|----------|-------------|
| EMAIL_SMTP | SMTP host |
| EMAIL_SMTP_PORT | SMTP port |
| EMAIL_SMTP_USERNAME | SMTP username |
| EMAIL_SMTP_PASSWORD | SMTP password |
| EMAIL_SMTP_DISPLAY_NAME | From display name (defaults) |
Exports
EmailModule— Register the email moduleEmailService— Send emails and verify connectionEmailConfig— Mailer configuration factory
Related Packages
- @zola_do/core — Shared types
