|
@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
|
|
|
|
|
|
|
|
## EmailPlugin
|
|
## EmailPlugin
|
|
|
|
|
|
|
|
-<GenerationInfo sourceFile="packages/email-plugin/src/plugin.ts" sourceLine="276" packageName="@vendure/email-plugin" />
|
|
|
|
|
|
|
+<GenerationInfo sourceFile="packages/email-plugin/src/plugin.ts" sourceLine="272" packageName="@vendure/email-plugin" />
|
|
|
|
|
|
|
|
The EmailPlugin creates and sends transactional emails based on Vendure events. By default, it uses an [MJML](https://mjml.io/)-based
|
|
The EmailPlugin creates and sends transactional emails based on Vendure events. By default, it uses an [MJML](https://mjml.io/)-based
|
|
|
email generator to generate the email body and [Nodemailer](https://nodemailer.com/about/) to send the emails.
|
|
email generator to generate the email body and [Nodemailer](https://nodemailer.com/about/) to send the emails.
|
|
@@ -20,13 +20,13 @@ email generator to generate the email body and [Nodemailer](https://nodemailer.c
|
|
|
Vendure has an internal events system (see <a href='/reference/typescript-api/events/event-bus#eventbus'>EventBus</a>) that allows plugins to subscribe to events. The EmailPlugin is configured with <a href='/reference/core-plugins/email-plugin/email-event-handler#emaileventhandler'>EmailEventHandler</a>s
|
|
Vendure has an internal events system (see <a href='/reference/typescript-api/events/event-bus#eventbus'>EventBus</a>) that allows plugins to subscribe to events. The EmailPlugin is configured with <a href='/reference/core-plugins/email-plugin/email-event-handler#emaileventhandler'>EmailEventHandler</a>s
|
|
|
that listen for a specific event and when it is published, the handler defines which template to use to generate the resulting email.
|
|
that listen for a specific event and when it is published, the handler defines which template to use to generate the resulting email.
|
|
|
|
|
|
|
|
-The plugin comes with a set of default handlers for the following events:
|
|
|
|
|
|
|
+The plugin comes with a set of default handler for the following events:
|
|
|
- Order confirmation
|
|
- Order confirmation
|
|
|
- New customer email address verification
|
|
- New customer email address verification
|
|
|
- Password reset request
|
|
- Password reset request
|
|
|
- Email address change request
|
|
- Email address change request
|
|
|
|
|
|
|
|
-You can also create your own handlers and register them with the plugin - see the <a href='/reference/core-plugins/email-plugin/email-event-handler#emaileventhandler'>EmailEventHandler</a> docs for more details.
|
|
|
|
|
|
|
+You can also create your own handler and register them with the plugin - see the <a href='/reference/core-plugins/email-plugin/email-event-handler#emaileventhandler'>EmailEventHandler</a> docs for more details.
|
|
|
|
|
|
|
|
## Installation
|
|
## Installation
|
|
|
|
|
|
|
@@ -45,7 +45,7 @@ const config: VendureConfig = {
|
|
|
// Add an instance of the plugin to the plugins array
|
|
// Add an instance of the plugin to the plugins array
|
|
|
plugins: [
|
|
plugins: [
|
|
|
EmailPlugin.init({
|
|
EmailPlugin.init({
|
|
|
- handlers: defaultEmailHandlers,
|
|
|
|
|
|
|
+ handler: defaultEmailHandlers,
|
|
|
templatePath: path.join(__dirname, 'static/email/templates'),
|
|
templatePath: path.join(__dirname, 'static/email/templates'),
|
|
|
transport: {
|
|
transport: {
|
|
|
type: 'smtp',
|
|
type: 'smtp',
|
|
@@ -110,21 +110,21 @@ The following helper functions are available for use in email templates:
|
|
|
* `formatMoney`: Formats an amount of money (which are always stored as integers in Vendure) as a decimal, e.g. `123` => `1.23`
|
|
* `formatMoney`: Formats an amount of money (which are always stored as integers in Vendure) as a decimal, e.g. `123` => `1.23`
|
|
|
* `formatDate`: Formats a Date value with the [dateformat](https://www.npmjs.com/package/dateformat) package.
|
|
* `formatDate`: Formats a Date value with the [dateformat](https://www.npmjs.com/package/dateformat) package.
|
|
|
|
|
|
|
|
-## Extending the default email handlers
|
|
|
|
|
|
|
+## Extending the default email handler
|
|
|
|
|
|
|
|
-The `defaultEmailHandlers` array defines the default handlers such as for handling new account registration, order confirmation, password reset
|
|
|
|
|
|
|
+The `defaultEmailHandlers` array defines the default handler such as for handling new account registration, order confirmation, password reset
|
|
|
etc. These defaults can be extended by adding custom templates for languages other than the default, or even completely new types of emails
|
|
etc. These defaults can be extended by adding custom templates for languages other than the default, or even completely new types of emails
|
|
|
which respond to any of the available [VendureEvents](/reference/typescript-api/events/).
|
|
which respond to any of the available [VendureEvents](/reference/typescript-api/events/).
|
|
|
|
|
|
|
|
-A good way to learn how to create your own email handlers is to take a look at the
|
|
|
|
|
-[source code of the default handlers](https://github.com/vendure-ecommerce/vendure/blob/master/packages/email-plugin/src/default-email-handlers.ts).
|
|
|
|
|
-New handlers are defined in exactly the same way.
|
|
|
|
|
|
|
+A good way to learn how to create your own email handler is to take a look at the
|
|
|
|
|
+[source code of the default handler](https://github.com/vendure-ecommerce/vendure/blob/master/packages/email-plugin/src/default-email-handlers.ts).
|
|
|
|
|
+New handler are defined in exactly the same way.
|
|
|
|
|
|
|
|
-It is also possible to modify the default handlers:
|
|
|
|
|
|
|
+It is also possible to modify the default handler:
|
|
|
|
|
|
|
|
```ts
|
|
```ts
|
|
|
// Rather than importing `defaultEmailHandlers`, you can
|
|
// Rather than importing `defaultEmailHandlers`, you can
|
|
|
-// import the handlers individually
|
|
|
|
|
|
|
+// import the handler individually
|
|
|
import {
|
|
import {
|
|
|
orderConfirmationHandler,
|
|
orderConfirmationHandler,
|
|
|
emailVerificationHandler,
|
|
emailVerificationHandler,
|
|
@@ -151,10 +151,10 @@ const myPasswordResetHandler = passwordResetHandler
|
|
|
customer: event.data.customer,
|
|
customer: event.data.customer,
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
-// Then you pass the handlers to the EmailPlugin init method
|
|
|
|
|
|
|
+// Then you pass the handler to the EmailPlugin init method
|
|
|
// individually
|
|
// individually
|
|
|
EmailPlugin.init({
|
|
EmailPlugin.init({
|
|
|
- handlers: [
|
|
|
|
|
|
|
+ handler: [
|
|
|
myOrderConfirmationHandler,
|
|
myOrderConfirmationHandler,
|
|
|
myPasswordResetHandler,
|
|
myPasswordResetHandler,
|
|
|
emailVerificationHandler,
|
|
emailVerificationHandler,
|
|
@@ -179,7 +179,7 @@ import { MyTransportService } from './transport.services.ts';
|
|
|
const config: VendureConfig = {
|
|
const config: VendureConfig = {
|
|
|
plugins: [
|
|
plugins: [
|
|
|
EmailPlugin.init({
|
|
EmailPlugin.init({
|
|
|
- handlers: defaultEmailHandlers,
|
|
|
|
|
|
|
+ handler: defaultEmailHandlers,
|
|
|
templatePath: path.join(__dirname, 'static/email/templates'),
|
|
templatePath: path.join(__dirname, 'static/email/templates'),
|
|
|
transport: (injector, ctx) => {
|
|
transport: (injector, ctx) => {
|
|
|
if (ctx) {
|
|
if (ctx) {
|
|
@@ -207,7 +207,7 @@ file transport (See <a href='/reference/core-plugins/email-plugin/transport-opti
|
|
|
EmailPlugin.init({
|
|
EmailPlugin.init({
|
|
|
devMode: true,
|
|
devMode: true,
|
|
|
route: 'mailbox',
|
|
route: 'mailbox',
|
|
|
- handlers: defaultEmailHandlers,
|
|
|
|
|
|
|
+ handler: defaultEmailHandlers,
|
|
|
templatePath: path.join(__dirname, 'vendure/email/templates'),
|
|
templatePath: path.join(__dirname, 'vendure/email/templates'),
|
|
|
outputPath: path.join(__dirname, 'test-emails'),
|
|
outputPath: path.join(__dirname, 'test-emails'),
|
|
|
})
|
|
})
|