feat(smtp): add optional sender display name to SMTP configuration
Closes #3600. Previously the From header on test emails and notifications showed only the raw email address. Adds an optional "Sender name" field so emails appear from a friendly name like "Checkmate notifications" <user@example.org>. ## Behaviour - Field is optional. When empty/null/whitespace, the From header falls back to the raw email address — identical to current behaviour, no regression for existing installs. - When set, the email service hands nodemailer { name, address } as the message from field. Nodemailer handles RFC-5322 encoding (quotes, commas, non-ASCII) so the display name is safe for any input. - Unsetting works: clearing the input transforms the value to null in the Zod parse step, and the settings repository already turns null values into a $unset operation. - Both client and server Zod schemas trim and empty-string-to-null, preventing whitespace-only display names from being stored. ## Surfaces - AppSettings schema, Settings type, EmailTransportConfig pick, server Zod validation, client Zod validation, client form defaults, and the Settings page form all carry the new systemEmailDisplayName field. - The transport preview pre-block on /settings now includes a `from` key showing exactly what the email service hands nodemailer — the string when no display name is set, or { name, address } when it is. - en.json carries the new label and placeholder. Other locales fall back until translated (16 locales pending — separate follow-up). ## Conventions conformance (per docs/frontend-conventions.md) - The pre-block I touched had three rule #1 violations (sx p, borderRadius, backgroundColor); hoisted those to native props using theme.shape.borderRadius. Other rule #1 violations elsewhere on this page are pre-existing and intentionally left alone. - No new sx-with-native-equivalents introduced. - No color="text.X" shorthand introduced. - No theme module import introduced.
This commit is contained in:
1 parent
8ca62db317
commit
e71892d0bc
10 files changed
+90
-39
No files matched your search
@@ -18,6 +18,7 @@ export const useSettingsForm = ({ data = null }: UseSettingsFormOptions = {}) =>
|
|||||||
systemEmailHost: data?.systemEmailHost || "",
|
systemEmailHost: data?.systemEmailHost || "",
|
||||||
systemEmailUser: data?.systemEmailUser || "",
|
systemEmailUser: data?.systemEmailUser || "",
|
||||||
systemEmailAddress: data?.systemEmailAddress || "",
|
systemEmailAddress: data?.systemEmailAddress || "",
|
||||||
|
systemEmailDisplayName: data?.systemEmailDisplayName || "",
|
||||||
systemEmailConnectionHost: data?.systemEmailConnectionHost || "localhost",
|
systemEmailConnectionHost: data?.systemEmailConnectionHost || "localhost",
|
||||||
systemEmailTLSServername: data?.systemEmailTLSServername || "",
|
systemEmailTLSServername: data?.systemEmailTLSServername || "",
|
||||||
systemEmailPort: data?.systemEmailPort,
|
systemEmailPort: data?.systemEmailPort,
|
||||||
|
|||||||
@@ -182,6 +182,9 @@ export const SettingsPage = () => {
|
|||||||
systemEmailRequireTLS: formValues.systemEmailRequireTLS,
|
systemEmailRequireTLS: formValues.systemEmailRequireTLS,
|
||||||
systemEmailRejectUnauthorized: formValues.systemEmailRejectUnauthorized,
|
systemEmailRejectUnauthorized: formValues.systemEmailRejectUnauthorized,
|
||||||
...(formValues.systemEmailUser && { systemEmailUser: formValues.systemEmailUser }),
|
...(formValues.systemEmailUser && { systemEmailUser: formValues.systemEmailUser }),
|
||||||
|
...(formValues.systemEmailDisplayName && {
|
||||||
|
systemEmailDisplayName: formValues.systemEmailDisplayName,
|
||||||
|
}),
|
||||||
...(formValues.systemEmailTLSServername && {
|
...(formValues.systemEmailTLSServername && {
|
||||||
systemEmailTLSServername: formValues.systemEmailTLSServername,
|
systemEmailTLSServername: formValues.systemEmailTLSServername,
|
||||||
}),
|
}),
|
||||||
@@ -577,44 +580,50 @@ export const SettingsPage = () => {
|
|||||||
href="https://nodemailer.com/smtp/"
|
href="https://nodemailer.com/smtp/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
/>
|
/>
|
||||||
<Box
|
{(() => {
|
||||||
component="pre"
|
const address = form.watch("systemEmailAddress") || "";
|
||||||
sx={{
|
const displayName = form.watch("systemEmailDisplayName")?.trim();
|
||||||
fontFamily: theme.typography.fontFamilyMonospace,
|
const from =
|
||||||
p: 2,
|
displayName && address ? { name: displayName, address } : address;
|
||||||
borderRadius: 1,
|
return (
|
||||||
overflow: "auto",
|
<Box
|
||||||
backgroundColor: theme.palette.action.hover,
|
component="pre"
|
||||||
}}
|
p={2}
|
||||||
>
|
borderRadius={theme.shape.borderRadius}
|
||||||
<code>
|
bgcolor={theme.palette.action.hover}
|
||||||
{JSON.stringify(
|
sx={{
|
||||||
{
|
fontFamily: theme.typography.fontFamilyMonospace,
|
||||||
host: form.watch("systemEmailHost") || "",
|
overflow: "auto",
|
||||||
port: form.watch("systemEmailPort") || "",
|
}}
|
||||||
secure: form.watch("systemEmailSecure") ?? false,
|
>
|
||||||
auth: {
|
<code>
|
||||||
user:
|
{JSON.stringify(
|
||||||
form.watch("systemEmailUser") ||
|
{
|
||||||
form.watch("systemEmailAddress") ||
|
host: form.watch("systemEmailHost") || "",
|
||||||
"",
|
port: form.watch("systemEmailPort") || "",
|
||||||
pass: "<your_password>",
|
secure: form.watch("systemEmailSecure") ?? false,
|
||||||
},
|
auth: {
|
||||||
name: form.watch("systemEmailConnectionHost") || "localhost",
|
user: form.watch("systemEmailUser") || address,
|
||||||
pool: form.watch("systemEmailPool") ?? false,
|
pass: "<your_password>",
|
||||||
tls: {
|
},
|
||||||
rejectUnauthorized:
|
name: form.watch("systemEmailConnectionHost") || "localhost",
|
||||||
form.watch("systemEmailRejectUnauthorized") ?? true,
|
pool: form.watch("systemEmailPool") ?? false,
|
||||||
ignoreTLS: form.watch("systemEmailIgnoreTLS") ?? false,
|
from,
|
||||||
requireTLS: form.watch("systemEmailRequireTLS") ?? false,
|
tls: {
|
||||||
servername: form.watch("systemEmailTLSServername") || "",
|
rejectUnauthorized:
|
||||||
},
|
form.watch("systemEmailRejectUnauthorized") ?? true,
|
||||||
},
|
ignoreTLS: form.watch("systemEmailIgnoreTLS") ?? false,
|
||||||
null,
|
requireTLS: form.watch("systemEmailRequireTLS") ?? false,
|
||||||
2
|
servername: form.watch("systemEmailTLSServername") || "",
|
||||||
)}
|
},
|
||||||
</code>
|
},
|
||||||
</Box>
|
null,
|
||||||
|
2
|
||||||
|
)}
|
||||||
|
</code>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
rightContent={
|
rightContent={
|
||||||
@@ -680,6 +689,24 @@ export const SettingsPage = () => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Email Display Name (Optional) */}
|
||||||
|
<Controller
|
||||||
|
name="systemEmailDisplayName"
|
||||||
|
control={form.control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
value={field.value ?? ""}
|
||||||
|
fieldLabel={t("pages.settings.form.email.option.displayName.label")}
|
||||||
|
placeholder={t(
|
||||||
|
"pages.settings.form.email.option.displayName.placeholder"
|
||||||
|
)}
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Email User (Optional) */}
|
{/* Email User (Optional) */}
|
||||||
<Controller
|
<Controller
|
||||||
name="systemEmailUser"
|
name="systemEmailUser"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export interface Settings {
|
|||||||
systemEmailHost?: string;
|
systemEmailHost?: string;
|
||||||
systemEmailPort?: number;
|
systemEmailPort?: number;
|
||||||
systemEmailAddress?: string;
|
systemEmailAddress?: string;
|
||||||
|
systemEmailDisplayName?: string;
|
||||||
systemEmailUser?: string;
|
systemEmailUser?: string;
|
||||||
systemEmailConnectionHost?: string;
|
systemEmailConnectionHost?: string;
|
||||||
systemEmailTLSServername?: string;
|
systemEmailTLSServername?: string;
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ export const settingsSchema = z.object({
|
|||||||
.or(z.literal(""))
|
.or(z.literal(""))
|
||||||
.transform((val) => (val === "" ? null : val.toLowerCase().trim()))
|
.transform((val) => (val === "" ? null : val.toLowerCase().trim()))
|
||||||
.optional(),
|
.optional(),
|
||||||
|
systemEmailDisplayName: z
|
||||||
|
.string()
|
||||||
|
.max(100, "Display name must be 100 characters or fewer")
|
||||||
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
|
.optional(),
|
||||||
systemEmailUser: z
|
systemEmailUser: z
|
||||||
.string()
|
.string()
|
||||||
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
|
|||||||
@@ -1198,6 +1198,10 @@
|
|||||||
"label": "Email address - Used for authentication",
|
"label": "Email address - Used for authentication",
|
||||||
"placeholder": "you@example.com"
|
"placeholder": "you@example.com"
|
||||||
},
|
},
|
||||||
|
"displayName": {
|
||||||
|
"label": "Sender name (optional) - Friendly name shown in the From field",
|
||||||
|
"placeholder": "Checkmate notifications"
|
||||||
|
},
|
||||||
"user": {
|
"user": {
|
||||||
"label": "Email user - Username for authentication, overrides email address if specified",
|
"label": "Email user - Username for authentication, overrides email address if specified",
|
||||||
"placeholder": "Leave empty if not required"
|
"placeholder": "Leave empty if not required"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const AppSettingsSchema = new Schema<AppSettingsDocument>(
|
|||||||
systemEmailHost: { type: String },
|
systemEmailHost: { type: String },
|
||||||
systemEmailPort: { type: Number },
|
systemEmailPort: { type: Number },
|
||||||
systemEmailAddress: { type: String },
|
systemEmailAddress: { type: String },
|
||||||
|
systemEmailDisplayName: { type: String },
|
||||||
systemEmailPassword: { type: String },
|
systemEmailPassword: { type: String },
|
||||||
systemEmailUser: { type: String },
|
systemEmailUser: { type: String },
|
||||||
systemEmailConnectionHost: { type: String, default: "localhost" },
|
systemEmailConnectionHost: { type: String, default: "localhost" },
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export class EmailService implements IEmailService {
|
|||||||
systemEmailPool,
|
systemEmailPool,
|
||||||
systemEmailUser,
|
systemEmailUser,
|
||||||
systemEmailAddress,
|
systemEmailAddress,
|
||||||
|
systemEmailDisplayName,
|
||||||
systemEmailPassword,
|
systemEmailPassword,
|
||||||
systemEmailConnectionHost,
|
systemEmailConnectionHost,
|
||||||
systemEmailTLSServername,
|
systemEmailTLSServername,
|
||||||
@@ -158,10 +159,13 @@ export class EmailService implements IEmailService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const trimmedDisplayName = systemEmailDisplayName?.trim();
|
||||||
|
const from = trimmedDisplayName && systemEmailAddress ? { name: trimmedDisplayName, address: systemEmailAddress } : systemEmailAddress;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const info = await this.transporter.sendMail({
|
const info = await this.transporter.sendMail({
|
||||||
to: to,
|
to: to,
|
||||||
from: systemEmailAddress,
|
from: from,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
html: html,
|
html: html,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export type EmailTransportConfig = Pick<
|
|||||||
| "systemEmailHost"
|
| "systemEmailHost"
|
||||||
| "systemEmailPort"
|
| "systemEmailPort"
|
||||||
| "systemEmailAddress"
|
| "systemEmailAddress"
|
||||||
|
| "systemEmailDisplayName"
|
||||||
| "systemEmailPassword"
|
| "systemEmailPassword"
|
||||||
| "systemEmailUser"
|
| "systemEmailUser"
|
||||||
| "systemEmailConnectionHost"
|
| "systemEmailConnectionHost"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface Settings {
|
|||||||
systemEmailHost?: string;
|
systemEmailHost?: string;
|
||||||
systemEmailPort?: number;
|
systemEmailPort?: number;
|
||||||
systemEmailAddress?: string;
|
systemEmailAddress?: string;
|
||||||
|
systemEmailDisplayName?: string;
|
||||||
systemEmailPassword?: string;
|
systemEmailPassword?: string;
|
||||||
systemEmailUser?: string;
|
systemEmailUser?: string;
|
||||||
systemEmailConnectionHost?: string;
|
systemEmailConnectionHost?: string;
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ export const updateAppSettingsBodyValidation = z
|
|||||||
timezone: z.string().optional(),
|
timezone: z.string().optional(),
|
||||||
systemEmailHost: z.string().nullable().optional(),
|
systemEmailHost: z.string().nullable().optional(),
|
||||||
systemEmailAddress: z.string().nullable().optional(),
|
systemEmailAddress: z.string().nullable().optional(),
|
||||||
|
systemEmailDisplayName: z
|
||||||
|
.string()
|
||||||
|
.max(100)
|
||||||
|
.transform((val) => (val.trim() === "" ? null : val.trim()))
|
||||||
|
.nullable()
|
||||||
|
.optional(),
|
||||||
systemEmailPassword: z.string().nullable().optional(),
|
systemEmailPassword: z.string().nullable().optional(),
|
||||||
systemEmailUser: z.string().nullable().optional(),
|
systemEmailUser: z.string().nullable().optional(),
|
||||||
systemEmailConnectionHost: z.string().nullable().optional(),
|
systemEmailConnectionHost: z.string().nullable().optional(),
|
||||||
|
|||||||
Reference in new issue
Block a user