From ae1e4e90c0fcb0d55167bba16b3b47bff9c31f36 Mon Sep 17 00:00:00 2001 From: Ivan Polchenko <2119240+i5okie@users.noreply.github.com> Date: Mon, 5 Feb 2024 08:57:24 -0800 Subject: [PATCH] Conditionally add auth only if credentials are set Signed-off-by: Ivan Polchenko <2119240+i5okie@users.noreply.github.com> --- services/tenant-ui/src/components/email.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/services/tenant-ui/src/components/email.ts b/services/tenant-ui/src/components/email.ts index 4b30c266e..92c4d6a29 100644 --- a/services/tenant-ui/src/components/email.ts +++ b/services/tenant-ui/src/components/email.ts @@ -73,15 +73,23 @@ export const sendConfirmationEmail = async (req: Request) => { */ export const sendStatusEmail = async (req: Request) => { try { - const transporter = nodemailer.createTransport({ + + // Prepare the transport configuration + let transportConfig = { host: SERVER, port: PORT, secure: SECURE, - auth: { + }; + + // Add auth only if user and password are set + if (USER !== "" && PASSWORD !== "") { + transportConfig.auth = { user: USER, pass: PASSWORD, - }, - }); + }; + } + + const transporter = nodemailer.createTransport(transportConfig); let template; let subject;