Merge pull request #2427 from bluewave-labs/feat/test-email

Feat: New Email Options
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-06-15 17:11:12 +08:00
commit 1607aba78f
9 files changed
+204 -53

No files matched your search

+105 -23
View File
@@ -12,6 +12,7 @@ import { useTranslation } from "react-i18next";
import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments"; import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments";
import { useSendTestEmail } from "../../Hooks/useSendTestEmail"; import { useSendTestEmail } from "../../Hooks/useSendTestEmail";
import { createToast } from "../../Utils/toastUtils"; import { createToast } from "../../Utils/toastUtils";
import { Switch } from "@mui/material";
const SettingsEmail = ({ const SettingsEmail = ({
isAdmin, isAdmin,
@@ -25,6 +26,21 @@ const SettingsEmail = ({
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme = useTheme();
// Destructure settings with default values
const {
systemEmailHost = "",
systemEmailPort = "",
systemEmailSecure = false,
systemEmailPool = false,
systemEmailUser = "",
systemEmailAddress = "",
systemEmailPassword = "",
systemEmailTLSServername = "",
systemEmailConnectionHost = "localhost",
systemEmailIgnoreTLS = false,
systemEmailRequireTLS = false,
systemEmailRejectUnauthorized = true,
} = settingsData?.settings || {};
// Local state // Local state
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [hasBeenReset, setHasBeenReset] = useState(false); const [hasBeenReset, setHasBeenReset] = useState(false);
@@ -47,18 +63,32 @@ const SettingsEmail = ({
const handleSendTestEmail = () => { const handleSendTestEmail = () => {
// Collect current form values // Collect current form values
const emailConfig = { const emailConfig = {
systemEmailHost: settingsData?.settings?.systemEmailHost, systemEmailHost,
systemEmailPort: settingsData?.settings?.systemEmailPort, systemEmailPort,
systemEmailUser: settingsData?.settings?.systemEmailUser, systemEmailSecure,
systemEmailAddress: settingsData?.settings?.systemEmailAddress, systemEmailPool,
systemEmailPassword: password || settingsData?.settings?.systemEmailPassword, systemEmailUser,
systemEmailConnectionHost: settingsData?.settings?.systemEmailConnectionHost, systemEmailAddress,
systemEmailPassword: password || systemEmailPassword,
systemEmailTLSServername,
systemEmailConnectionHost,
systemEmailIgnoreTLS,
systemEmailRequireTLS,
systemEmailRejectUnauthorized,
}; };
// Basic validation // Basic validation
if (!emailConfig.systemEmailHost || !emailConfig.systemEmailPort) { if (
!emailConfig.systemEmailHost ||
!emailConfig.systemEmailPort ||
!emailConfig.systemEmailAddress ||
!emailConfig.systemEmailPassword
) {
createToast({ createToast({
body: t("settingsEmailRequiredFields", "Email host and port are required"), body: t(
"settingsEmailRequiredFields",
"Email address, host, port and password are required"
),
variant: "error", variant: "error",
}); });
return; return;
@@ -90,7 +120,7 @@ const SettingsEmail = ({
<TextInput <TextInput
name="systemEmailHost" name="systemEmailHost"
placeholder="smtp.gmail.com" placeholder="smtp.gmail.com"
value={settingsData?.settings?.systemEmailHost ?? ""} value={systemEmailHost}
onChange={handleChange} onChange={handleChange}
/> />
</Box> </Box>
@@ -100,7 +130,7 @@ const SettingsEmail = ({
name="systemEmailPort" name="systemEmailPort"
placeholder="425" placeholder="425"
type="number" type="number"
value={settingsData?.settings?.systemEmailPort ?? ""} value={systemEmailPort}
onChange={handleChange} onChange={handleChange}
/> />
</Box> </Box>
@@ -109,7 +139,7 @@ const SettingsEmail = ({
<TextInput <TextInput
name="systemEmailUser" name="systemEmailUser"
placeholder="Leave empty if not required" placeholder="Leave empty if not required"
value={settingsData?.settings?.systemEmailUser ?? ""} value={systemEmailUser}
onChange={handleChange} onChange={handleChange}
/> />
</Box> </Box>
@@ -118,7 +148,7 @@ const SettingsEmail = ({
<TextInput <TextInput
name="systemEmailAddress" name="systemEmailAddress"
placeholder="uptime@bluewavelabs.ca" placeholder="uptime@bluewavelabs.ca"
value={settingsData?.settings?.systemEmailAddress ?? ""} value={systemEmailAddress}
onChange={handleChange} onChange={handleChange}
/> />
</Box> </Box>
@@ -156,23 +186,75 @@ const SettingsEmail = ({
</Box> </Box>
)} )}
<Box> <Box>
<Typography>{t("settingsEmailConnectionHost")}</Typography> <Typography>{t("settingsEmailTLSServername")}</Typography>
<TextInput <TextInput
name="systemEmailConnectionHost" name="systemEmailTLSServername"
placeholder="bluewavelabs.ca" placeholder="bluewavelabs.ca"
value={settingsData?.settings?.systemEmailConnectionHost ?? ""} value={systemEmailTLSServername}
onChange={handleChange} onChange={handleChange}
/> />
</Box> </Box>
<Box> <Box>
<Button <Typography>{t("settingsEmailConnectionHost")}</Typography>
variant="contained" <TextInput
color="accent" name="systemEmailConnectionHost"
loading={isSending} placeholder="bluewavelabs.ca"
onClick={handleSendTestEmail} value={systemEmailConnectionHost}
> onChange={handleChange}
{t("settingsTestEmail", "Send test e-mail")} />
</Button> </Box>
<Box
sx={{
display: "flex",
flexDirection: "column",
gap: theme.spacing(4),
}}
>
<Typography>{t("settingsEmailSecure")}</Typography>
<Switch
name="systemEmailSecure"
checked={systemEmailSecure}
onChange={handleChange}
/>
<Typography>{t("settingsEmailPool")}</Typography>
<Switch
name="systemEmailPool"
checked={systemEmailPool}
onChange={handleChange}
/>
<Typography>{t("settingsEmailIgnoreTLS")}</Typography>
<Switch
name="systemEmailIgnoreTLS"
checked={systemEmailIgnoreTLS}
onChange={handleChange}
/>
<Typography>{t("settingsEmailRequireTLS")}</Typography>
<Switch
name="systemEmailRequireTLS"
checked={systemEmailRequireTLS}
onChange={handleChange}
/>
<Typography>{t("settingsEmailRejectUnauthorized")}</Typography>
<Switch
name="systemEmailRejectUnauthorized"
checked={systemEmailRejectUnauthorized}
onChange={handleChange}
/>
</Box>
<Box>
{systemEmailHost &&
systemEmailPort &&
systemEmailAddress &&
systemEmailPassword && (
<Button
variant="contained"
color="accent"
loading={isSending}
onClick={handleSendTestEmail}
>
{t("settingsTestEmail", "Send test e-mail")}
</Button>
)}
</Box> </Box>
</Stack> </Stack>
</Box> </Box>
+12 -2
View File
@@ -56,17 +56,27 @@ const Settings = () => {
// Handlers // Handlers
const handleChange = async (e) => { const handleChange = async (e) => {
const { name, value } = e.target; const { name, value, checked } = e.target;
// Special case for showURL until handled properly in the backend // Special case for showURL until handled properly in the backend
if (name === "showURL") { if (name === "showURL") {
dispatch(setShowURL(value)); dispatch(setShowURL(value));
return; return;
} }
let newValue;
if (
name === "systemEmailIgnoreTLS" ||
name === "systemEmailRequireTLS" ||
name === "systemEmailRejectUnauthorized" ||
name === "systemEmailSecure" ||
name === "systemEmailPool"
) {
newValue = checked;
}
// Build next state early // Build next state early
const newSettingsData = { const newSettingsData = {
...settingsData, ...settingsData,
settings: { ...settingsData.settings, [name]: value }, settings: { ...settingsData.settings, [name]: newValue ?? value },
}; };
// Validate // Validate
+6 -4
View File
@@ -973,10 +973,12 @@ class NetworkService {
systemEmailPort: emailConfig.systemEmailPort, systemEmailPort: emailConfig.systemEmailPort,
systemEmailAddress: emailConfig.systemEmailAddress, systemEmailAddress: emailConfig.systemEmailAddress,
systemEmailPassword: emailConfig.systemEmailPassword, systemEmailPassword: emailConfig.systemEmailPassword,
// Only include these if they are present systemEmailSecure: emailConfig.systemEmailSecure,
...(emailConfig.systemEmailConnectionHost && { systemEmailPool: emailConfig.systemEmailPool,
systemEmailConnectionHost: emailConfig.systemEmailConnectionHost, systemEmailIgnoreTLS: emailConfig.systemEmailIgnoreTLS,
}), systemEmailRequireTLS: emailConfig.systemEmailRequireTLS,
systemEmailRejectUnauthorized: emailConfig.systemEmailRejectUnauthorized,
systemEmailTLSServername: emailConfig.systemEmailTLSServername,
...(emailConfig.systemEmailUser && { ...(emailConfig.systemEmailUser && {
systemEmailUser: emailConfig.systemEmailUser, systemEmailUser: emailConfig.systemEmailUser,
}), }),
+7 -1
View File
@@ -290,10 +290,16 @@ const settingsValidation = joi.object({
timezone: joi.string().allow("").optional(), timezone: joi.string().allow("").optional(),
systemEmailHost: joi.string().allow(""), systemEmailHost: joi.string().allow(""),
systemEmailPort: joi.number().allow(null, ""), systemEmailPort: joi.number().allow(null, ""),
systemEmailSecure: joi.boolean().optional(),
systemEmailPool: joi.boolean().optional(),
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(""), systemEmailConnectionHost: joi.string().allow("").optional(),
systemEmailTLSServername: joi.string().allow(""),
systemEmailIgnoreTLS: joi.boolean(),
systemEmailRequireTLS: joi.boolean(),
systemEmailRejectUnauthorized: joi.boolean(),
}); });
const dayjsValidator = (value, helpers) => { const dayjsValidator = (value, helpers) => {
+8 -2
View File
@@ -681,12 +681,18 @@
}, },
"settingsEmail": "Email", "settingsEmail": "Email",
"settingsEmailDescription": "Configure the email settings for your system. This is used to send notifications and alerts.", "settingsEmailDescription": "Configure the email settings for your system. This is used to send notifications and alerts.",
"settingsEmailHost": "Email host - Hostname or IP address of the SMTP server", "settingsEmailHost": "Email host - Hostname or IP address to connect to",
"settingsEmailPort": "Email port - Port to connect to", "settingsEmailPort": "Email port - Port to connect to",
"settingsEmailAddress": "Email address - Used for authentication", "settingsEmailAddress": "Email address - Used for authentication",
"settingsEmailPassword": "Email password - Password for authentication", "settingsEmailPassword": "Email password - Password for authentication",
"settingsEmailUser": "Email user - Username for authentication, overrides email address if specified", "settingsEmailUser": "Email user - Username for authentication, overrides email address if specified",
"settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.", "settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.",
"settingsEmailTLSServername": "TLS Servername - Optional Hostname for TLS Validation when host is an IP",
"settingsEmailIgnoreTLS": "Ignore TLS - Disable STARTTLS",
"settingsEmailRequireTLS": "Require TLS - Force STARTTLS",
"settingsEmailRejectUnauthorized": "Reject Unauthorized",
"settingsEmailSecure": "Secure - Use SSL",
"settingsEmailPool": "Pool - Enable connection pooling",
"state": "State", "state": "State",
"statusBreadCrumbsStatusPages": "Status Pages", "statusBreadCrumbsStatusPages": "Status Pages",
"statusBreadCrumbsDetails": "Details", "statusBreadCrumbsDetails": "Details",
@@ -716,7 +722,7 @@
"settingsTestEmailFailed": "Failed to send test email", "settingsTestEmailFailed": "Failed to send test email",
"settingsTestEmailFailedWithReason": "Failed to send test email: {{reason}}", "settingsTestEmailFailedWithReason": "Failed to send test email: {{reason}}",
"settingsTestEmailUnknownError": "Unknown error", "settingsTestEmailUnknownError": "Unknown error",
"settingsEmailRequiredFields": "Email host and port are required", "settingsEmailRequiredFields": "Email address, host, port and password are required",
"statusMsg": { "statusMsg": {
"paused": "Monitoring is paused.", "paused": "Monitoring is paused.",
"up": "Your site is up.", "up": "Your site is up.",
+12
View File
@@ -74,6 +74,12 @@ class SettingsController {
systemEmailPassword, systemEmailPassword,
systemEmailUser, systemEmailUser,
systemEmailConnectionHost, systemEmailConnectionHost,
systemEmailSecure,
systemEmailPool,
systemEmailIgnoreTLS,
systemEmailRequireTLS,
systemEmailRejectUnauthorized,
systemEmailTLSServername,
} = req.body; } = req.body;
const subject = this.stringService.testEmailSubject; const subject = this.stringService.testEmailSubject;
@@ -91,6 +97,12 @@ class SettingsController {
systemEmailAddress, systemEmailAddress,
systemEmailPassword, systemEmailPassword,
systemEmailConnectionHost, systemEmailConnectionHost,
systemEmailSecure,
systemEmailPool,
systemEmailIgnoreTLS,
systemEmailRequireTLS,
systemEmailRejectUnauthorized,
systemEmailTLSServername,
} }
); );
+23
View File
@@ -32,6 +32,29 @@ const AppSettingsSchema = mongoose.Schema(
type: String, type: String,
default: "localhost", default: "localhost",
}, },
systemEmailTLSServername: {
type: String,
},
systemEmailSecure: {
type: Boolean,
default: false,
},
systemEmailPool: {
type: Boolean,
default: false,
},
systemEmailIgnoreTLS: {
type: Boolean,
default: false,
},
systemEmailRequireTLS: {
type: Boolean,
default: false,
},
systemEmailRejectUnauthorized: {
type: Boolean,
default: true,
},
singleton: { singleton: {
type: Boolean, type: Boolean,
required: true, required: true,
+17 -19
View File
@@ -101,39 +101,37 @@ class EmailService {
const { const {
systemEmailHost, systemEmailHost,
systemEmailPort, systemEmailPort,
systemEmailSecure,
systemEmailPool,
systemEmailUser, systemEmailUser,
systemEmailAddress, systemEmailAddress,
systemEmailPassword, systemEmailPassword,
systemEmailConnectionHost, systemEmailConnectionHost,
systemEmailTLSServername,
systemEmailIgnoreTLS,
systemEmailRequireTLS,
systemEmailRejectUnauthorized,
} = config; } = config;
const baseEmailConfig = { const emailConfig = {
host: systemEmailHost, host: systemEmailHost,
port: systemEmailPort, port: Number(systemEmailPort),
secure: true, secure: systemEmailSecure,
auth: { auth: {
user: systemEmailUser || systemEmailAddress, user: systemEmailUser || systemEmailAddress,
pass: systemEmailPassword, pass: systemEmailPassword,
}, },
name: systemEmailConnectionHost || "localhost",
connectionTimeout: 5000, connectionTimeout: 5000,
pool: systemEmailPool,
tls: {
rejectUnauthorized: systemEmailRejectUnauthorized,
ignoreTLS: systemEmailIgnoreTLS,
requireTLS: systemEmailRequireTLS,
servername: systemEmailTLSServername,
},
}; };
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) => {
+14 -2
View File
@@ -410,7 +410,13 @@ 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(""), systemEmailConnectionHost: joi.string().allow("").optional(),
systemEmailTLSServername: joi.string().allow("").optional(),
systemEmailSecure: joi.boolean(),
systemEmailPool: joi.boolean(),
systemEmailIgnoreTLS: joi.boolean(),
systemEmailRequireTLS: joi.boolean(),
systemEmailRejectUnauthorized: joi.boolean(),
}); });
//**************************************** //****************************************
@@ -612,10 +618,16 @@ const sendTestEmailBodyValidation = joi.object({
to: joi.string().required(), to: joi.string().required(),
systemEmailHost: joi.string(), systemEmailHost: joi.string(),
systemEmailPort: joi.number(), systemEmailPort: joi.number(),
systemEmailSecure: joi.boolean(),
systemEmailPool: joi.boolean(),
systemEmailAddress: joi.string(), systemEmailAddress: joi.string(),
systemEmailPassword: joi.string(), systemEmailPassword: joi.string(),
systemEmailUser: joi.string(), systemEmailUser: joi.string(),
systemEmailConnectionHost: joi.string(), systemEmailConnectionHost: joi.string().allow("").optional(),
systemEmailIgnoreTLS: joi.boolean(),
systemEmailRequireTLS: joi.boolean(),
systemEmailRejectUnauthorized: joi.boolean(),
systemEmailTLSServername: joi.string().allow("").optional(),
}); });
export { export {