How to create email templates for transactional emails

Use email templates with variable replacement for sending email campaigns with personalized messages. Email templating tutorial.

Please see the template controller in the API documentation.

Creating templates

Use the MailSlurp API to create email templates.

await mailslurp.templateController.createTemplate({
  createTemplateOptions: {
    name: 'Welcome',
    content: 'Welcome to our app',
  },
});

Templates support moustache syntax variable replacement.

Sending with templates

Sending is easy:

const templateObject = await mailslurp.templateController.getTemplate({
  templateId,
});
expect(templateObject.content).toContain(
  'Hello {{firstName}}. Welcome to {{brandName}}.'
);
const sent = await mailslurp.sendEmail(inboxId, {
  to: [emailAddress],
  subject: 'Welcome {{firstName}}',
  template: templateId,
  templateVariables: {
    firstName: 'Sally',
    brandName: 'My Company',
  } as any,
});

More examples

See the examples repository for more information.