Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client/src/Pages/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ export const SettingsPage = () => {
if (
!formValues.systemEmailHost ||
!formValues.systemEmailPort ||
!formValues.systemEmailAddress ||
!formValues.systemEmailPassword
!formValues.systemEmailAddress
) {
alert("Please fill in all required email fields before testing.");
return;
Expand All @@ -198,12 +197,14 @@ export const SettingsPage = () => {
systemEmailHost: formValues.systemEmailHost,
systemEmailPort: formValues.systemEmailPort,
systemEmailAddress: formValues.systemEmailAddress,
systemEmailPassword: formValues.systemEmailPassword,
systemEmailSecure: formValues.systemEmailSecure,
systemEmailPool: formValues.systemEmailPool,
systemEmailIgnoreTLS: formValues.systemEmailIgnoreTLS,
systemEmailRequireTLS: formValues.systemEmailRequireTLS,
systemEmailRejectUnauthorized: formValues.systemEmailRejectUnauthorized,
...(formValues.systemEmailPassword && {
systemEmailPassword: formValues.systemEmailPassword,
}),
...(formValues.systemEmailUser && { systemEmailUser: formValues.systemEmailUser }),
...(formValues.systemEmailDisplayName && {
systemEmailDisplayName: formValues.systemEmailDisplayName,
Expand Down Expand Up @@ -749,8 +750,7 @@ export const SettingsPage = () => {
disabled={
!form.watch("systemEmailHost") ||
!form.watch("systemEmailPort") ||
!form.watch("systemEmailAddress") ||
!form.watch("systemEmailPassword")
!form.watch("systemEmailAddress")
}
>
{t("common.buttons.sendTestEmail")}
Expand Down
10 changes: 6 additions & 4 deletions server/src/service/emailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ export class EmailService implements IEmailService {
host: systemEmailHost,
port: Number(systemEmailPort),
secure: systemEmailSecure,
auth: {
user: systemEmailUser || systemEmailAddress,
pass: systemEmailPassword,
},
...(systemEmailPassword && {
auth: {
user: systemEmailUser || systemEmailAddress,
pass: systemEmailPassword,
},
}),
name: systemEmailConnectionHost || "localhost",
connectionTimeout: 5000,
pool: systemEmailPool,
Expand Down
27 changes: 27 additions & 0 deletions server/test/unit/services/emailService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,33 @@ describe("EmailService", () => {
);
});

it("omits auth from the transport config when no password is configured", async () => {
const transporter = createMockTransporter();
const nodemailer = createMockNodemailer(transporter);
const { service } = createService({ nodemailer });
const config = makeTransportConfig({ systemEmailPassword: undefined });

await service.sendEmail("to@example.com", "Subject", "<p>body</p>", config);

const transportArg = (nodemailer.createTransport as jest.Mock).mock.calls[0]?.[0] as Record<string, unknown>;
expect(transportArg).not.toHaveProperty("auth");
});

it("includes auth in the transport config when a password is configured", async () => {
const transporter = createMockTransporter();
const nodemailer = createMockNodemailer(transporter);
const { service } = createService({ nodemailer });
const config = makeTransportConfig({ systemEmailPassword: "password123" });

await service.sendEmail("to@example.com", "Subject", "<p>body</p>", config);

expect(nodemailer.createTransport).toHaveBeenCalledWith(
expect.objectContaining({
auth: { user: "user@example.com", pass: "password123" },
})
);
});

it("uses 'localhost' as name when systemEmailConnectionHost is falsy", async () => {
const transporter = createMockTransporter();
const nodemailer = createMockNodemailer(transporter);
Expand Down
Loading