feat(notifications): allow SMTP without authentication

Some SMTP relays (e.g. Google SMTP Relay with IP allowlisting) do not
use username/password authentication. Make both fields optional in the
email notification form and API schema, and only pass auth to
nodemailer when credentials are provided.

Closes #4842
This commit is contained in:
hbilal9 2026-07-18 11:48:38 +05:00
parent df3965a581
commit 40fd2089fa
3 changed files with 25 additions and 12 deletions

View File

@ -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) => {
<FormItem className="w-full">
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="username" {...field} />
<Input
placeholder="username"
{...field}
value={field.value ?? ""}
/>
</FormControl>
<FormDescription>
Optional. Leave blank if your SMTP server does not
require authentication.
</FormDescription>
<FormMessage />
</FormItem>
)}
@ -1146,9 +1153,13 @@ export const HandleNotifications = ({ notificationId }: Props) => {
type="password"
placeholder="******************"
{...field}
value={field.value ?? ""}
/>
</FormControl>
<FormDescription>
Optional. Leave blank if your SMTP server does not
require authentication.
</FormDescription>
<FormMessage />
</FormItem>
)}
@ -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,
});

View File

@ -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),
})

View File

@ -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({