@haykal/email-backend
v1.0.0
Published
Reusable email sending package with provider abstraction, template rendering, and queue integration.
Readme
@haykal/email-backend
Reusable email sending package with provider abstraction, template rendering, and queue integration.
Features
- Provider abstraction — SMTP (nodemailer), Resend, Mailhog (development)
- Template rendering — Handlebars with file-based & database template sources
- Email logging — Track all sent emails with status and provider info
- Admin API — Template management and preview endpoints
- Queue-ready — Optional integration with
@haykal/jobs-backendfor reliable delivery
Usage
import { EmailModule } from '@haykal/email-backend';
@Module({
imports: [
EmailModule.forRoot({
provider: 'smtp',
from: { name: 'My App', email: '[email protected]' },
smtp: {
host: 'localhost',
port: 1025,
secure: false,
},
enableLogging: true,
}),
],
})
export class AppModule {}Key Exports
| Export | Type | Description |
| ------------------------- | ------------- | ----------------------------------------------- |
| EmailModule | NestJS Module | Main module with forRoot() / forRootAsync() |
| EMAIL_CONFIG | Symbol | Inject the config object |
| EmailService | Service | Send emails (raw or template-rendered) |
| EmailTemplatesService | Service | Template CRUD |
| TemplateRendererService | Service | Handlebars template rendering |
| EmailLogEntity | Entity | Email send log records |
| EmailTemplateEntity | Entity | Email templates |
| EMAIL_ENTITIES | Array | Entities for migration discovery |
Related Packages
@haykal/email-client— React Query hooks for email management@haykal/jobs-backend— Queue integration for reliable delivery@haykal/notifications-backend— Uses email as a notification channel@haykal/core-backend— Base infrastructure
Further Reading
- API Reference — Full endpoint listing
- Backend Style Guide — Coding conventions
