fix: added email connection validation

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

View File

@@ -278,7 +278,7 @@ const settingsValidation = joi.object({
systemEmailAddress: joi.string().allow(""),
systemEmailPassword: joi.string().allow(""),
systemEmailUser: joi.string().allow(""),
systemEmailConnectionHost: joi.string().allow("").optional(),
systemEmailConnectionHost: joi.string().allow(""),
});
const dayjsValidator = (value, helpers) => {
@@ -308,7 +308,7 @@ const advancedSettingsValidation = joi.object({
systemEmailPort: joi.number().allow(null, ""),
systemEmailAddress: joi.string().allow(""),
systemEmailPassword: joi.string().allow(""),
systemEmailConnectionHost: joi.string().allow("").optional(),
systemEmailConnectionHost: joi.string().allow(""),
jwtTTLNum: joi.number().messages({
"number.base": "JWT TTL is required.",
}),

View File

@@ -30,6 +30,7 @@ const AppSettingsSchema = mongoose.Schema(
},
systemEmailConnectionHost: {
type: String,
default: "localhost",
},
singleton: {
type: Boolean,

View File

@@ -11,6 +11,7 @@ const SERVICE_NAME = "EmailService";
*/
class EmailService {
static SERVICE_NAME = SERVICE_NAME;
/**
* Constructs an instance of the EmailService, initializing template loaders and the email transporter.
* @param {Object} settingsService - The settings service to get email configuration.
@@ -96,7 +97,7 @@ class EmailService {
systemEmailUser,
systemEmailAddress,
systemEmailPassword,
systemEmailConnectionHost
systemEmailConnectionHost,
} = await this.settingsService.getDBSettings();
const baseEmailConfig = {
@@ -112,13 +113,15 @@ class EmailService {
const isSmtps = Number(systemEmailPort) === 465;
const emailConfig = !isSmtps ? {
...baseEmailConfig,
name: systemEmailConnectionHost || "127.0.0.1",
secure: false,
pool: true,
tls: { rejectUnauthorized: false },
} : baseEmailConfig;
const emailConfig = !isSmtps
? {
...baseEmailConfig,
name: systemEmailConnectionHost || "localhost",
secure: false,
pool: true,
tls: { rejectUnauthorized: false },
}
: baseEmailConfig;
if (!isSmtps) {
delete emailConfig.auth;
@@ -164,4 +167,5 @@ class EmailService {
return info?.messageId;
};
}
export default EmailService;