@joktec/mailer
v0.2.17
Published
JokTec - Mailer Service
Maintainers
Readme
@joktec/mailer
Mailer adapter package for JokTec applications.
@joktec/mailer wraps Nodemailer with JokTec config parsing, lifecycle hooks, optional template compilation, preview support, and a reusable send contract.
What It Provides
MailerModuleglobal Nest module.MailerServicebuilt onAbstractClientService.- SMTP, auth, OAuth2, template, preview, and transport config models.
- Mail client interface and mailer exception types.
- Template support for Handlebars, EJS, and Pug stores.
Install
yarn add @joktec/mailerUsage
import { MailerModule, MailerService } from '@joktec/mailer';
@Module({
imports: [MailerModule],
})
export class AppModule {}Inject MailerService into app services:
await mailerService.send({
to: '[email protected]',
subject: 'Welcome',
html: '<p>Hello</p>',
});Template rendering can be used when template config is enabled:
const html = await mailerService.compile({
name: 'welcome',
context: { name: 'JokTec' },
});Config
Configure the mailer section in the application config. Multiple connections are selected with conId.
mailer:
conId: default
host: smtp.example.com
port: 587
secure: false
sender: [email protected]
auth:
user: smtp-user
pass: smtp-password
template:
dir: ./templates
engine: hbsGuidelines
- Keep mail composition and business events in the consuming app.
- Do not commit SMTP credentials or OAuth2 secrets.
- Use preview mode only in development.
- Prefer sending mail from worker/microservice processes when delivery should not block request handling.
Development
yarn lint --scope @joktec/mailer
yarn build --scope @joktec/mailer
yarn test --scope @joktec/mailer