From 74989012220317f741dee110321ac07cec52acfd Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Thu, 29 Jun 2023 10:48:03 +0200 Subject: [PATCH] fix(email-plugin): Add warning when running devMode with transport Fixes #2253 --- packages/email-plugin/src/email-processor.ts | 29 ++++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/packages/email-plugin/src/email-processor.ts b/packages/email-plugin/src/email-processor.ts index d57c242e18..da421853ef 100644 --- a/packages/email-plugin/src/email-processor.ts +++ b/packages/email-plugin/src/email-processor.ts @@ -29,12 +29,6 @@ import { export class EmailProcessor { protected emailSender: EmailSender; protected generator: EmailGenerator; - protected transport: - | EmailTransportOptions - | (( - injector?: Injector, - ctx?: RequestContext, - ) => EmailTransportOptions | Promise); constructor( @Inject(EMAIL_PLUGIN_OPTIONS) protected options: InitializedEmailPluginOptions, @@ -49,20 +43,6 @@ export class EmailProcessor { if (this.generator.onInit) { await this.generator.onInit.call(this.generator, this.options); } - if (isDevModeOptions(this.options)) { - this.transport = { - type: 'file', - raw: false, - outputPath: this.options.outputPath, - }; - } else { - if (!this.options.transport) { - throw new InternalServerError( - "When devMode is not set to true, the 'transport' property must be set.", - ); - } - this.transport = this.options.transport; - } const transport = await this.getTransportSettings(); if (transport.type === 'file') { // ensure the configured directory exists before @@ -106,14 +86,21 @@ export class EmailProcessor { } async getTransportSettings(ctx?: RequestContext): Promise { + const transport = await resolveTransportSettings(this.options, new Injector(this.moduleRef), ctx); if (isDevModeOptions(this.options)) { + if (transport && transport.type !== 'file') { + Logger.warn( + `The EmailPlugin is running in dev mode. The configured '${transport.type}' transport will be replaced by the 'file' transport.`, + loggerCtx, + ); + } return { type: 'file', raw: false, outputPath: this.options.outputPath, }; } else { - return resolveTransportSettings(this.options, new Injector(this.moduleRef), ctx); + return transport; } } }