EmailTypes

EmailTypes

An object describing each possible type of transactional email, plus which events trigger those emails, as well as the location of the templates to handle each email type. Search the repo for the default-email-types.ts file for an example of how the email types are defined.

When defining an email type, the helper function configEmailType may be used to provide better type-safety.

Example

export const defaultEmailTypes: EmailTypes<DefaultEmailType> = {
 'order-confirmation': configEmailType({
   triggerEvent: OrderStateTransitionEvent,
   createContext: e => {
     const customer = e.order.customer;
     if (customer && e.toState === 'PaymentSettled') {
       return {
         recipient: customer.emailAddress,
         languageCode: e.ctx.languageCode,
         channelCode: e.ctx.channel.code,
       };
     }
   },
   templates: {
     defaultChannel: {
       defaultLanguage: {
         templateContext: emailContext => ({ order: emailContext.event.order }),
         subject: `Order confirmation for #{{ order.code }}`,
         templatePath: 'order-confirmation/order-confirmation.hbs',
       },
       de: {
         // config for German-language templates
       }
     },
     'other-channel-code': {
       // config for a different Channel
     }
   },
 }),

Signature

type EmailTypes<T extends string> = { [emailType in T]: EmailTypeConfig<T> }
alpha