From 457036805980b19511b3a2d9cda397c3d0d66647 Mon Sep 17 00:00:00 2001 From: FRITZ|FRITZ Date: Wed, 29 May 2024 06:22:47 -0400 Subject: [PATCH 1/3] Allow Insecure Mail Transport Changed the transport builder to be more flexible. > Defaults to secure = true if mail.secure is not specified > Does not require auth to be specified if not needed --- utils/mail/mailer.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/utils/mail/mailer.js b/utils/mail/mailer.js index ac68100..7d4063a 100644 --- a/utils/mail/mailer.js +++ b/utils/mail/mailer.js @@ -188,12 +188,25 @@ export default class NewsletterMailer { * @returns {Promise<*>} - The configured transporter. */ async #transporter(mailConfig) { - return nodemailer.createTransport({ - secure: true, - host: mailConfig.host, - port: mailConfig.port, - auth: {user: mailConfig.auth.user, pass: mailConfig.auth.pass} - }); + // Destructure from mailConfig, defaulting secure to true if not specified + const { secure = true, host, port, auth } = mailConfig; + + // Initialize transport options + const transportOptions = { + secure, + host, + port + }; + + // Conditionally add auth if both user and pass are provided + if (auth && auth.user && auth.pass) { + transportOptions.auth = { + user: auth.user, + pass: auth.pass + }; + } + + return nodemailer.createTransport(transportOptions); } /** @@ -256,4 +269,4 @@ export default class NewsletterMailer { return emailsSent; } -} \ No newline at end of file +} From fb929b48f1ddda1b4d9b6987fbb2eda64df6fd1f Mon Sep 17 00:00:00 2001 From: fritz-fritz Date: Fri, 31 May 2024 04:13:37 -0400 Subject: [PATCH 2/3] Update Settings View to Support Insecure and No Auth Mail Servers Use case is mainly for when the mail server is on localhost and no auth or security is required. This updates the form so that it can be configured successfully from the browser instead of only from the configuration file. --- views/dashboard/settings.ejs | 19 +++++++++++++++---- views/partials/settings/mail.ejs | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/views/dashboard/settings.ejs b/views/dashboard/settings.ejs index 6bf6f4b..83aab0b 100644 --- a/views/dashboard/settings.ejs +++ b/views/dashboard/settings.ejs @@ -46,7 +46,7 @@ +
+
+ ].secure)) { %> checked + <% } %> + > + +
+
+
@@ -70,7 +81,7 @@ Password @@ -107,4 +118,4 @@ class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded mt-4">Add New - \ No newline at end of file + From 8a72f8f8f0184bf68d97893f9438d81f2e53b4b6 Mon Sep 17 00:00:00 2001 From: fritz-fritz Date: Fri, 31 May 2024 05:14:39 -0400 Subject: [PATCH 3/3] Fix EJS variables and Config Writing --- utils/data/configs.js | 7 ++++--- views/dashboard/settings.ejs | 2 +- views/partials/settings/mail.ejs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/data/configs.js b/utils/data/configs.js index 86454cb..4abbfc4 100644 --- a/utils/data/configs.js +++ b/utils/data/configs.js @@ -228,7 +228,7 @@ export default class ProjectConfigs { configs.custom_template.enabled = customTemplateEnabled === 'on' ?? false; // mail configurations - configs.mail = [...email.map(({batch_size, delay_per_batch, auth_user, auth_pass, ...rest}) => { + configs.mail = [...email.map(({batch_size, delay_per_batch, auth_user, auth_pass, secure, ...rest}) => { return { ...rest, batch_size: parseInt(batch_size), @@ -236,7 +236,8 @@ export default class ProjectConfigs { auth: { user: auth_user, pass: auth_pass - } + }, + secure: secure === 'on' ? true : false }; })]; @@ -311,4 +312,4 @@ export default class ProjectConfigs { this.ghoslerVersion = JSON.parse(fileContent).version; }).catch((_) => this.ghoslerVersion = ''); } -} \ No newline at end of file +} diff --git a/views/dashboard/settings.ejs b/views/dashboard/settings.ejs index 83aab0b..02f8b99 100644 --- a/views/dashboard/settings.ejs +++ b/views/dashboard/settings.ejs @@ -68,7 +68,7 @@
checked + <% if (Boolean(configs.mail[configs.mail.length - 1].secure)) { %> checked <% } %> > diff --git a/views/partials/settings/mail.ejs b/views/partials/settings/mail.ejs index d9621e2..b95b2b6 100644 --- a/views/partials/settings/mail.ejs +++ b/views/partials/settings/mail.ejs @@ -60,7 +60,7 @@
].secure)) { %> checked + <% if (Boolean(configs.mail[index].secure)) { %> checked <% } %> >