fix: added email connection validation
This commit is contained in:
3 files changed
+15
-10
No files matched your search
@@ -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.",
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const AppSettingsSchema = mongoose.Schema(
|
|||||||
},
|
},
|
||||||
systemEmailConnectionHost: {
|
systemEmailConnectionHost: {
|
||||||
type: String,
|
type: String,
|
||||||
|
default: "localhost",
|
||||||
},
|
},
|
||||||
singleton: {
|
singleton: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in new issue
Block a user