email-plugin-options.md 6.0 KB


title: "EmailPluginOptions" isDefaultIndex: false

generated: true

import MemberInfo from '@site/src/components/MemberInfo'; import GenerationInfo from '@site/src/components/GenerationInfo'; import MemberDescription from '@site/src/components/MemberDescription';

EmailPluginOptions

Configuration for the EmailPlugin.

interface EmailPluginOptions {
    templatePath?: string;
    templateLoader?: TemplateLoader;
    transport:
        | EmailTransportOptions
        | ((
              injector?: Injector,
              ctx?: RequestContext,
          ) => EmailTransportOptions | Promise<EmailTransportOptions>);
    handlers: Array<EmailEventHandler<string, any>>;
    globalTemplateVars?: { [key: string]: any } | GlobalTemplateVarsFn;
    emailSender?: EmailSender;
    emailGenerator?: EmailGenerator;
}
### templatePath The path to the location of the email templates. In a default Vendure installation, the templates are installed to `/vendure/email/templates`. ### templateLoader TemplateLoader`} since="2.0.0" /> An optional TemplateLoader which can be used to load templates from a custom location or async service. The default uses the FileBasedTemplateLoader which loads templates from `/vendure/email/templates` ### transport EmailTransportOptions | (( injector?: Injector, ctx?: RequestContext, ) => EmailTransportOptions | Promise<EmailTransportOptions>)`} /> Configures how the emails are sent. ### handlers EmailEventHandler<string, any>>`} /> An array of EmailEventHandlers which define which Vendure events will trigger emails, and how those emails are generated. ### globalTemplateVars GlobalTemplateVarsFn`} /> An object containing variables which are made available to all templates. For example, the storefront URL could be defined here and then used in the "email address verification" email. Use the GlobalTemplateVarsFn if you need to retrieve variables from Vendure or plugin services. ### emailSender EmailSender`} default={`NodemailerEmailSender`} /> An optional allowed EmailSender, used to allow custom implementations of the send functionality while still utilizing the existing emailPlugin functionality. ### emailGenerator EmailGenerator`} default={`HandlebarsMjmlGenerator`} /> An optional allowed EmailGenerator, used to allow custom email generation functionality to better match with custom email sending functionality.

GlobalTemplateVarsFn

Allows you to dynamically load the "globalTemplateVars" key async and access Vendure services to create the object. This is not a requirement. You can also specify a simple static object if your projects doesn't need to access async or dynamic values.

Example


EmailPlugin.init({
   globalTemplateVars: async (ctx, injector) => {
         const myAsyncService = injector.get(MyAsyncService);
         const asyncValue = await myAsyncService.get(ctx);
         const channel = ctx.channel;
         const { primaryColor } = channel.customFields.theme;
         const theme = {
             primaryColor,
             asyncValue,
         };
         return theme;
     }
  [...]
})

type GlobalTemplateVarsFn = (
    ctx: RequestContext,
    injector: Injector,
) => Promise<{ [key: string]: any }>

EmailPluginDevModeOptions

Configuration for running the EmailPlugin in development mode.

interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'transport'> {
    devMode: true;
    outputPath: string;
    route: string;
}
### devMode ### outputPath The path to which html email files will be saved rather than being sent. ### route The route to the dev mailbox server.