From ce5c5d60420675a3703a551bd1f21aa333b6f8ed Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 3 Nov 2021 14:00:16 +0000 Subject: [PATCH] Server: Disable mailer service if no-reply email is not set --- packages/server/src/services/EmailService.ts | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/server/src/services/EmailService.ts b/packages/server/src/services/EmailService.ts index b1e49e111..443ce6902 100644 --- a/packages/server/src/services/EmailService.ts +++ b/packages/server/src/services/EmailService.ts @@ -20,17 +20,21 @@ export default class EmailService extends BaseService { private async transport(): Promise { if (!this.transport_) { - this.transport_ = createTransport({ - host: this.config.mailer.host, - port: this.config.mailer.port, - secure: this.config.mailer.secure, - auth: { - user: this.config.mailer.authUser, - pass: this.config.mailer.authPassword, - }, - }); - try { + if (!this.senderInfo(EmailSender.NoReply).email) { + throw new Error('No-reply email must be set for email service to work (Set env variable MAILER_NOREPLY_EMAIL)'); + } + + this.transport_ = createTransport({ + host: this.config.mailer.host, + port: this.config.mailer.port, + secure: this.config.mailer.secure, + auth: { + user: this.config.mailer.authUser, + pass: this.config.mailer.authPassword, + }, + }); + await this.transport_.verify(); logger.info('Transporter is operational - service will be enabled'); } catch (error) {