Implement a custom template adapter
mainTo use a template engine other than the ones officially provided, you must create a class that implements the TemplateAdapter interface. The core method to implement is compile(mail, callback, options), where you handle the template loading and rendering logic, eventually passing the rendered HTML back via the callback.
import { MailerOptions, TemplateAdapter } from '@nestjs-modules/mailer';
export class MyCustomAdapter implements TemplateAdapter {
compile(
mail: any,
callback: (err?: any, body?: string) => any,
options: MailerOptions,
): void {
// 1. Extract template info from mail.data.template
// 2. Render template using your engine
// 3. Call callback(null, renderedHtml) or callback(error)
}
}