|
@@ -4,10 +4,16 @@ import fs from 'fs-extra';
|
|
|
import { deserializeAttachments } from './attachment-utils';
|
|
import { deserializeAttachments } from './attachment-utils';
|
|
|
import { isDevModeOptions } from './common';
|
|
import { isDevModeOptions } from './common';
|
|
|
import { loggerCtx } from './constants';
|
|
import { loggerCtx } from './constants';
|
|
|
-import { EmailSender } from './email-sender';
|
|
|
|
|
|
|
+import { DefaultEmailSender } from './email-sender';
|
|
|
import { HandlebarsMjmlGenerator } from './handlebars-mjml-generator';
|
|
import { HandlebarsMjmlGenerator } from './handlebars-mjml-generator';
|
|
|
import { TemplateLoader } from './template-loader';
|
|
import { TemplateLoader } from './template-loader';
|
|
|
-import { EmailPluginOptions, EmailTransportOptions, IntermediateEmailDetails } from './types';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ EmailGenerator,
|
|
|
|
|
+ EmailPluginOptions,
|
|
|
|
|
+ EmailSender,
|
|
|
|
|
+ EmailTransportOptions,
|
|
|
|
|
+ IntermediateEmailDetails,
|
|
|
|
|
+} from './types';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* This class combines the template loading, generation, and email sending - the actual "work" of
|
|
* This class combines the template loading, generation, and email sending - the actual "work" of
|
|
@@ -17,15 +23,17 @@ import { EmailPluginOptions, EmailTransportOptions, IntermediateEmailDetails } f
|
|
|
export class EmailProcessor {
|
|
export class EmailProcessor {
|
|
|
protected templateLoader: TemplateLoader;
|
|
protected templateLoader: TemplateLoader;
|
|
|
protected emailSender: EmailSender;
|
|
protected emailSender: EmailSender;
|
|
|
- protected generator: HandlebarsMjmlGenerator;
|
|
|
|
|
|
|
+ protected generator: EmailGenerator;
|
|
|
protected transport: EmailTransportOptions;
|
|
protected transport: EmailTransportOptions;
|
|
|
|
|
|
|
|
constructor(protected options: EmailPluginOptions) {}
|
|
constructor(protected options: EmailPluginOptions) {}
|
|
|
|
|
|
|
|
async init() {
|
|
async init() {
|
|
|
this.templateLoader = new TemplateLoader(this.options.templatePath);
|
|
this.templateLoader = new TemplateLoader(this.options.templatePath);
|
|
|
- this.emailSender = new EmailSender();
|
|
|
|
|
- this.generator = new HandlebarsMjmlGenerator();
|
|
|
|
|
|
|
+ this.emailSender = this.options.emailSender ? this.options.emailSender : new DefaultEmailSender();
|
|
|
|
|
+ this.generator = this.options.emailGenerator
|
|
|
|
|
+ ? this.options.emailGenerator
|
|
|
|
|
+ : new HandlebarsMjmlGenerator();
|
|
|
if (this.generator.onInit) {
|
|
if (this.generator.onInit) {
|
|
|
await this.generator.onInit.call(this.generator, this.options);
|
|
await this.generator.onInit.call(this.generator, this.options);
|
|
|
}
|
|
}
|