Mailer
The project uses @nestjs-modules/mailer with Handlebars templates. Emails are sent from the EmailService, which is called by the mail queue processor.
Configuration
Section titled “Configuration”mail.config.ts registers the mailer asynchronously. It reads SMTP settings from the environment and points the template adapter at src/common/modules/email/templates/.
MailerModule.forRootAsync(mailConfig.asProvider())Templates
Section titled “Templates”The starter includes two Handlebars templates:
verification.hbs— Renders the email verification OTP code.password-reset.hbs— Renders the password reset token.
Place new templates in the same folder and reference them by relative path when calling sendMail.
EmailService
Section titled “EmailService”EmailService wraps MailerService and provides three methods:
await this.emailService.sendEmail(to, subject, body);await this.emailService.sendVerificationEmail(to, code);await this.emailService.sendPasswordResetEmail(to, token);It logs success and errors. If the mailer throws, the error is logged but the queue processor’s retry logic is what ultimately decides whether the job is retried.
Adding a new template
Section titled “Adding a new template”- Create a new
.hbsfile undersrc/common/modules/email/templates/. - Add a method in
EmailServicethat callssendMailwith the template name and context. - Add a new job name and processor handler if the email is sent via the queue.
Testing locally
Section titled “Testing locally”For local development, use a test SMTP service such as Mailpit, Mailtrap, or Ethereal. Set the SMTP credentials in .env and restart the app. The queue processor will pick up jobs and send them through the configured transport.