From b39f5744ebe32bca23ed41268990f42a0c5f5433 Mon Sep 17 00:00:00 2001 From: aXenDeveloper Date: Tue, 11 Jun 2024 19:08:31 +0200 Subject: [PATCH] fix(mail): Create empty config mail when doesn't exists --- .../src/plugins/core/admin/email/mail.service.ts | 13 +++++++++++++ .../core/admin/email/settings/show/show.service.ts | 10 ---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/backend/src/plugins/core/admin/email/mail.service.ts b/backend/src/plugins/core/admin/email/mail.service.ts index 9ca8273c6..b035759a7 100644 --- a/backend/src/plugins/core/admin/email/mail.service.ts +++ b/backend/src/plugins/core/admin/email/mail.service.ts @@ -28,6 +28,19 @@ export class MailService { private readonly transporter: nodemailer.Transporter; constructor() { + if (!fs.existsSync(this.path)) { + // Create a default config file + fs.writeFileSync( + this.path, + JSON.stringify({ + smtp_host: "", + smtp_user: "", + smtp_secure: false, + smtp_port: 587 + }) + ); + } + const data = fs.readFileSync(this.path, "utf-8"); const config: ShowAdminEmailSettingsServiceObjWithPassword = JSON.parse(data); diff --git a/backend/src/plugins/core/admin/email/settings/show/show.service.ts b/backend/src/plugins/core/admin/email/settings/show/show.service.ts index f4077fbda..f60c04158 100644 --- a/backend/src/plugins/core/admin/email/settings/show/show.service.ts +++ b/backend/src/plugins/core/admin/email/settings/show/show.service.ts @@ -14,16 +14,6 @@ export class ShowAdminEmailSettingsService extends HelpersAdminEmailSettingsServ settings: { email: emailSettings } } = getConfigFile(); - if (!fs.existsSync(this.path)) { - return { - smtp_host: "", - smtp_user: "", - smtp_secure: false, - smtp_port: 587, - ...emailSettings - }; - } - const read = fs.readFileSync(this.path, "utf-8"); const config: ShowAdminEmailSettingsServiceObj = JSON.parse(read);