diff --git a/apps/dokploy/components/dashboard/settings/notifications/handle-notifications.tsx b/apps/dokploy/components/dashboard/settings/notifications/handle-notifications.tsx index c2e249c2d..942d240a2 100644 --- a/apps/dokploy/components/dashboard/settings/notifications/handle-notifications.tsx +++ b/apps/dokploy/components/dashboard/settings/notifications/handle-notifications.tsx @@ -89,8 +89,8 @@ export const notificationSchema = z.discriminatedUnion("type", [ type: z.literal("email"), smtpServer: z.string().min(1, { message: "SMTP Server is required" }), smtpPort: z.number().min(1, { message: "SMTP Port is required" }), - username: z.string().min(1, { message: "Username is required" }), - password: z.string().min(1, { message: "Password is required" }), + username: z.string().optional(), + password: z.string().optional(), fromAddress: z.string().min(1, { message: "From Address is required" }), toAddresses: z .array( @@ -640,8 +640,8 @@ export const HandleNotifications = ({ notificationId }: Props) => { volumeBackup: volumeBackup, smtpServer: data.smtpServer, smtpPort: data.smtpPort, - username: data.username, - password: data.password, + username: data.username || "", + password: data.password || "", fromAddress: data.fromAddress, toAddresses: data.toAddresses, name: data.name, @@ -1127,9 +1127,16 @@ export const HandleNotifications = ({ notificationId }: Props) => { Username - + - + + Optional. Leave blank if your SMTP server does not + require authentication. + )} @@ -1146,9 +1153,13 @@ export const HandleNotifications = ({ notificationId }: Props) => { type="password" placeholder="******************" {...field} + value={field.value ?? ""} /> - + + Optional. Leave blank if your SMTP server does not + require authentication. + )} @@ -2041,8 +2052,8 @@ export const HandleNotifications = ({ notificationId }: Props) => { await testEmailConnection({ smtpServer: data.smtpServer, smtpPort: data.smtpPort, - username: data.username, - password: data.password, + username: data.username || "", + password: data.password || "", fromAddress: data.fromAddress, toAddresses: data.toAddresses, }); diff --git a/packages/server/src/db/schema/notification.ts b/packages/server/src/db/schema/notification.ts index 3caf23d13..b252a1993 100644 --- a/packages/server/src/db/schema/notification.ts +++ b/packages/server/src/db/schema/notification.ts @@ -370,8 +370,8 @@ export const apiCreateEmail = notificationsSchema .extend({ smtpServer: z.string().min(1), smtpPort: z.number().min(1), - username: z.string().min(1), - password: z.string().min(1), + username: z.string(), + password: z.string(), fromAddress: z.string().min(1), toAddresses: z.array(z.string()).min(1), }) diff --git a/packages/server/src/utils/notifications/utils.ts b/packages/server/src/utils/notifications/utils.ts index d65258862..add43db28 100644 --- a/packages/server/src/utils/notifications/utils.ts +++ b/packages/server/src/utils/notifications/utils.ts @@ -33,7 +33,9 @@ export const sendEmailNotification = async ( const transporter = nodemailer.createTransport({ host: smtpServer, port: smtpPort, - auth: { user: username, pass: password }, + ...(username && password + ? { auth: { user: username, pass: password } } + : {}), }); await transporter.sendMail({