fix: added email connection validation

This commit is contained in:
Cahit Atilgan committed 2025-05-15 15:16:36 +02:00
1 parent 7327f24c47
commit e6b823d89e
3 files changed
+15 -10

No files matched your search

+2 -2
View File
@@ -278,7 +278,7 @@ const settingsValidation = joi.object({
systemEmailAddress: joi.string().allow(""), systemEmailAddress: joi.string().allow(""),
systemEmailPassword: joi.string().allow(""), systemEmailPassword: joi.string().allow(""),
systemEmailUser: joi.string().allow(""), systemEmailUser: joi.string().allow(""),
systemEmailConnectionHost: joi.string().allow("").optional(), systemEmailConnectionHost: joi.string().allow(""),
}); });
const dayjsValidator = (value, helpers) => { const dayjsValidator = (value, helpers) => {
@@ -308,7 +308,7 @@ const advancedSettingsValidation = joi.object({
systemEmailPort: joi.number().allow(null, ""), systemEmailPort: joi.number().allow(null, ""),
systemEmailAddress: joi.string().allow(""), systemEmailAddress: joi.string().allow(""),
systemEmailPassword: joi.string().allow(""), systemEmailPassword: joi.string().allow(""),
systemEmailConnectionHost: joi.string().allow("").optional(), systemEmailConnectionHost: joi.string().allow(""),
jwtTTLNum: joi.number().messages({ jwtTTLNum: joi.number().messages({
"number.base": "JWT TTL is required.", "number.base": "JWT TTL is required.",
}), }),
+1
View File
@@ -30,6 +30,7 @@ const AppSettingsSchema = mongoose.Schema(
}, },
systemEmailConnectionHost: { systemEmailConnectionHost: {
type: String, type: String,
default: "localhost",
}, },
singleton: { singleton: {
type: Boolean, type: Boolean,
+12 -8
View File
@@ -11,6 +11,7 @@ const SERVICE_NAME = "EmailService";
*/ */
class EmailService { class EmailService {
static SERVICE_NAME = SERVICE_NAME; static SERVICE_NAME = SERVICE_NAME;
/** /**
* Constructs an instance of the EmailService, initializing template loaders and the email transporter. * Constructs an instance of the EmailService, initializing template loaders and the email transporter.
* @param {Object} settingsService - The settings service to get email configuration. * @param {Object} settingsService - The settings service to get email configuration.
@@ -96,7 +97,7 @@ class EmailService {
systemEmailUser, systemEmailUser,
systemEmailAddress, systemEmailAddress,
systemEmailPassword, systemEmailPassword,
systemEmailConnectionHost systemEmailConnectionHost,
} = await this.settingsService.getDBSettings(); } = await this.settingsService.getDBSettings();
const baseEmailConfig = { const baseEmailConfig = {
@@ -112,13 +113,15 @@ class EmailService {
const isSmtps = Number(systemEmailPort) === 465; const isSmtps = Number(systemEmailPort) === 465;
const emailConfig = !isSmtps ? { const emailConfig = !isSmtps
...baseEmailConfig, ? {
name: systemEmailConnectionHost || "127.0.0.1", ...baseEmailConfig,
secure: false, name: systemEmailConnectionHost || "localhost",
pool: true, secure: false,
tls: { rejectUnauthorized: false }, pool: true,
} : baseEmailConfig; tls: { rejectUnauthorized: false },
}
: baseEmailConfig;
if (!isSmtps) { if (!isSmtps) {
delete emailConfig.auth; delete emailConfig.auth;
@@ -164,4 +167,5 @@ class EmailService {
return info?.messageId; return info?.messageId;
}; };
} }
export default EmailService; export default EmailService;