email-plugin-options.mdx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ---
  2. title: "EmailPluginOptions"
  3. generated: true
  4. ---
  5. <GenerationInfo sourceFile="packages/email-plugin/src/types.ts" sourceLine="77" packageName="@vendure/email-plugin" />
  6. Configuration for the EmailPlugin.
  7. ```ts title="Signature"
  8. interface EmailPluginOptions {
  9. templatePath?: string;
  10. templateLoader?: TemplateLoader;
  11. transport:
  12. | EmailTransportOptions
  13. | ((
  14. injector?: Injector,
  15. ctx?: RequestContext,
  16. ) => EmailTransportOptions | Promise<EmailTransportOptions>);
  17. handlers: Array<EmailEventHandler<string, any>>;
  18. globalTemplateVars?: { [key: string]: any } | GlobalTemplateVarsFn;
  19. emailSender?: EmailSender;
  20. emailGenerator?: EmailGenerator;
  21. }
  22. ```
  23. <div className="members-wrapper">
  24. ### templatePath
  25. <MemberInfo kind="property" type={`string`} />
  26. The path to the location of the email templates. In a default Vendure installation,
  27. the templates are installed to `<project root>/vendure/email/templates`.
  28. ### templateLoader
  29. <MemberInfo kind="property" type={`<a href='/reference/core-plugins/email-plugin/template-loader#templateloader'>TemplateLoader</a>`} since="2.0.0" />
  30. An optional TemplateLoader which can be used to load templates from a custom location or async service.
  31. The default uses the FileBasedTemplateLoader which loads templates from `<project root>/vendure/email/templates`
  32. ### transport
  33. <MemberInfo kind="property" type={`| <a href='/reference/core-plugins/email-plugin/transport-options#emailtransportoptions'>EmailTransportOptions</a> | (( injector?: <a href='/reference/typescript-api/common/injector#injector'>Injector</a>, ctx?: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, ) => <a href='/reference/core-plugins/email-plugin/transport-options#emailtransportoptions'>EmailTransportOptions</a> | Promise<<a href='/reference/core-plugins/email-plugin/transport-options#emailtransportoptions'>EmailTransportOptions</a>>)`} />
  34. Configures how the emails are sent.
  35. ### handlers
  36. <MemberInfo kind="property" type={`Array<<a href='/reference/core-plugins/email-plugin/email-event-handler#emaileventhandler'>EmailEventHandler</a><string, any>>`} />
  37. An array of [EmailEventHandler](/reference/core-plugins/email-plugin/email-event-handler#emaileventhandler)s which define which Vendure events will trigger
  38. emails, and how those emails are generated.
  39. ### globalTemplateVars
  40. <MemberInfo kind="property" type={`{ [key: string]: any } | <a href='/reference/core-plugins/email-plugin/email-plugin-options#globaltemplatevarsfn'>GlobalTemplateVarsFn</a>`} />
  41. An object containing variables which are made available to all templates. For example,
  42. the storefront URL could be defined here and then used in the "email address verification"
  43. email. Use the GlobalTemplateVarsFn if you need to retrieve variables from Vendure or
  44. plugin services.
  45. ### emailSender
  46. <MemberInfo kind="property" type={`<a href='/reference/core-plugins/email-plugin/email-sender#emailsender'>EmailSender</a>`} default={`<a href='/reference/core-plugins/email-plugin/email-sender#nodemaileremailsender'>NodemailerEmailSender</a>`} />
  47. An optional allowed EmailSender, used to allow custom implementations of the send functionality
  48. while still utilizing the existing emailPlugin functionality.
  49. ### emailGenerator
  50. <MemberInfo kind="property" type={`<a href='/reference/core-plugins/email-plugin/email-generator#emailgenerator'>EmailGenerator</a>`} default={`<a href='/reference/core-plugins/email-plugin/email-generator#handlebarsmjmlgenerator'>HandlebarsMjmlGenerator</a>`} />
  51. An optional allowed EmailGenerator, used to allow custom email generation functionality to
  52. better match with custom email sending functionality.
  53. </div>
  54. <GenerationInfo sourceFile="packages/email-plugin/src/types.ts" sourceLine="64" packageName="@vendure/email-plugin" since="2.3.0" />
  55. Allows you to dynamically load the "globalTemplateVars" key async and access Vendure services
  56. to create the object. This is not a requirement. You can also specify a simple static object if your
  57. projects doesn't need to access async or dynamic values.
  58. *Example*
  59. ```ts
  60. EmailPlugin.init({
  61. globalTemplateVars: async (ctx, injector) => {
  62. const myAsyncService = injector.get(MyAsyncService);
  63. const asyncValue = await myAsyncService.get(ctx);
  64. const channel = ctx.channel;
  65. const { primaryColor } = channel.customFields.theme;
  66. const theme = {
  67. primaryColor,
  68. asyncValue,
  69. };
  70. return theme;
  71. }
  72. [...]
  73. })
  74. ```
  75. ```ts title="Signature"
  76. type GlobalTemplateVarsFn = (
  77. ctx: RequestContext,
  78. injector: Injector,
  79. ) => Promise<{ [key: string]: any }>
  80. ```
  81. <GenerationInfo sourceFile="packages/email-plugin/src/types.ts" sourceLine="150" packageName="@vendure/email-plugin" />
  82. Configuration for running the EmailPlugin in development mode.
  83. ```ts title="Signature"
  84. interface EmailPluginDevModeOptions extends Omit<EmailPluginOptions, 'transport'> {
  85. devMode: true;
  86. outputPath: string;
  87. route: string;
  88. }
  89. ```
  90. * Extends: `Omit<`[`EmailPluginOptions`](/reference/core-plugins/email-plugin/email-plugin-options#emailpluginoptions)`, 'transport'>`
  91. <div className="members-wrapper">
  92. ### devMode
  93. <MemberInfo kind="property" type={`true`} />
  94. ### outputPath
  95. <MemberInfo kind="property" type={`string`} />
  96. The path to which html email files will be saved rather than being sent.
  97. ### route
  98. <MemberInfo kind="property" type={`string`} />
  99. The route to the dev mailbox server.
  100. </div>