Template Engines

All template engines implement the TemplateEngine interface:

interface TemplateEngine {
  render(template: string, data?: Record<string, unknown>): Promise<string>;
  renderFile(filePath: string, data?: Record<string, unknown>): Promise<string>;
  compile(template: string): (data?: Record<string, unknown>) => string;
}

Shared Configuration

Templates are configured via the templates key in MailConfig:

Mail.configure({
  // ... mailer config
  templates: {
    engine: 'handlebars', // or 'ejs', 'pug', or a TemplateEngine instance
    viewsPath: './views/emails',
    extension: '.hbs',
    cache: true,
  },
});

Note: You can also pass a custom TemplateEngine instance instead of a string:

import { HandlebarsEngine } from '@impruthvi/nodemail';

const engine = new HandlebarsEngine({ viewsPath: './emails' });
Mail.configure({
  // ...
  templates: { engine },
});