Merge pull request #2271 from catilgan-nextension/fix/nodemailer_relay

Enabling SMTP Relay with Nodemailer
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-05-15 09:39:01 -07:00
commit d48d3b9ff4
6 files changed
+37 -1

No files matched your search

@@ -122,6 +122,15 @@ const SettingsEmail = ({
</Button> </Button>
</Box> </Box>
)} )}
<Box>
<Typography>{t("systemEmailConnectionHost")}</Typography>
<TextInput
name="systemEmailConnectionHost"
placeholder="bluewavelabs.ca"
value={settingsData?.settings?.systemEmailConnectionHost ?? ""}
onChange={handleChange}
/>
</Box>
<Box> <Box>
<Button <Button
variant="contained" variant="contained"
+2
View File
@@ -278,6 +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(""),
}); });
const dayjsValidator = (value, helpers) => { const dayjsValidator = (value, helpers) => {
@@ -307,6 +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(""),
jwtTTLNum: joi.number().messages({ jwtTTLNum: joi.number().messages({
"number.base": "JWT TTL is required.", "number.base": "JWT TTL is required.",
}), }),
+1
View File
@@ -120,6 +120,7 @@
"settingsEmailPassword": "Email password", "settingsEmailPassword": "Email password",
"settingsEmailUser": "Email user", "settingsEmailUser": "Email user",
"settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.", "settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.",
"systemEmailConnectionHost":"Email connection host",
"backendUnreachable": "Server Connection Error", "backendUnreachable": "Server Connection Error",
"backendUnreachableMessage": "We're unable to connect to the server. Please check your internet connection or verify your deployment configuration if the problem persists.", "backendUnreachableMessage": "We're unable to connect to the server. Please check your internet connection or verify your deployment configuration if the problem persists.",
"backendUnreachableError": "Cannot connect to the server. Please try again later.", "backendUnreachableError": "Cannot connect to the server. Please try again later.",
+4
View File
@@ -28,6 +28,10 @@ const AppSettingsSchema = mongoose.Schema(
systemEmailUser: { systemEmailUser: {
type: String, type: String,
}, },
systemEmailConnectionHost: {
type: String,
default: "localhost",
},
singleton: { singleton: {
type: Boolean, type: Boolean,
required: true, required: true,
+20 -1
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,9 +97,10 @@ class EmailService {
systemEmailUser, systemEmailUser,
systemEmailAddress, systemEmailAddress,
systemEmailPassword, systemEmailPassword,
systemEmailConnectionHost,
} = await this.settingsService.getDBSettings(); } = await this.settingsService.getDBSettings();
const emailConfig = { const baseEmailConfig = {
host: systemEmailHost, host: systemEmailHost,
port: systemEmailPort, port: systemEmailPort,
secure: true, secure: true,
@@ -109,6 +111,22 @@ class EmailService {
connectionTimeout: 5000, connectionTimeout: 5000,
}; };
const isSmtps = Number(systemEmailPort) === 465;
const emailConfig = !isSmtps
? {
...baseEmailConfig,
name: systemEmailConnectionHost || "localhost",
secure: false,
pool: true,
tls: { rejectUnauthorized: false },
}
: baseEmailConfig;
if (!isSmtps) {
delete emailConfig.auth;
}
this.transporter = this.nodemailer.createTransport(emailConfig); this.transporter = this.nodemailer.createTransport(emailConfig);
const buildHtml = async (template, context) => { const buildHtml = async (template, context) => {
@@ -149,4 +167,5 @@ class EmailService {
return info?.messageId; return info?.messageId;
}; };
} }
export default EmailService; export default EmailService;
+1
View File
@@ -432,6 +432,7 @@ const updateAppSettingsBodyValidation = 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(""),
}); });
//**************************************** //****************************************