Email Notifications

Existing Templates

TemplateTrigger
welcome.hbsUser signup success
captcha.hbsSend verification code
user-delete.hbsAccount deletion confirmation
subscription-created.hbsSubscription created
subscription-renewed.hbsSubscription renewed
credit.hbsCredit purchase success
lifetime.hbsLifetime deal purchase
tenant-invitation.hbsOrganization invitation

Template location: api/src/config/mail/templates/

Add New Email

1. Create Template File

<!-- api/src/config/mail/templates/my-notification.hbs -->
<table width="100%" cellpadding="0" cellspacing="0" style="max-width:600px; margin:20px auto; background:#ffffff; border-radius:8px; overflow:hidden; box-shadow:0 2px 10px rgba(0,0,0,0.08);">
  <tr>
    <td style="padding:30px 20px;">
      <p style="font-size:16px; line-height:1.6; color:#333333;">Hi {{email}},</p>
      <p style="font-size:16px; line-height:1.6; color:#333333;">{{message}}</p>
    </td>
  </tr>
</table>

Templates use Handlebars syntax. {{variable}} inserts data.

2. Call MailService in Your Business Service

// api/src/services/my.service.ts
import { Injectable } from "@nestjs/common"
import { MailService } from "@readystart/api-core/shared/services/mail.service"

@Injectable()
export class MyService {
  constructor(private readonly mailService: MailService) {}

  async sendNotification(email: string, message: string) {
    const html = this.mailService.renderTemplate("my-notification", {
      email,
      message,
    })
    await this.mailService.sendMail({
      to: email,
      subject: "Notification",
      html,
    })
  }
}

No need to modify anything in libs/. Just inject MailService in your api/src/ business layer.

MailService API

// Render template
const html = this.mailService.renderTemplate("template-name", { key: "value" })

// Send email
await this.mailService.sendMail({
  to: "user@example.com",
  subject: "Subject",
  html: html,
})

Dev Mode

When MAIL_SEND_ENABLED=false, emails are not actually sent and the verification code is fixed at 123123.