Skip to content

Modern Docker Management, Designed for Everyone

fix: skip SMTP auth without full credentials and add none auth mode (#3192)

Kyle Mendellb501c49cc9f3
diff --git a/backend/internal/models/notification.go b/backend/internal/models/notification.go
index 7f83643ca..0db659488 100644
--- a/backend/internal/models/notification.go
+++ b/backend/internal/models/notification.go
@@ -58,6 +58,7 @@ const (
type EmailAuthMode string
const (
+ EmailAuthModeNone EmailAuthMode = "none"
EmailAuthModeAuto EmailAuthMode = "auto"
EmailAuthModePlain EmailAuthMode = "plain"
EmailAuthModeLogin EmailAuthMode = "login"
diff --git a/backend/internal/services/notification_service.go b/backend/internal/services/notification_service.go
index 46aeb735e..b5864e1ae 100644
--- a/backend/internal/services/notification_service.go
+++ b/backend/internal/services/notification_service.go
@@ -312,6 +312,9 @@ func encryptNotificationConfigCredentialsInternal(provider models.NotificationPr
if provider == models.NotificationProviderSignal {
preserveConfig = signalCredentialPreservationConfigInternal(config, existingConfig)
}
+ if provider == models.NotificationProviderEmail {
+ preserveConfig = emailCredentialPreservationConfigInternal(config, existingConfig)
+ }
for _, field := range notificationCredentialFieldsByProviderInternal[provider] {
value, _ := encryptedConfig[field].(string)
if value == "" {
@@ -346,6 +349,14 @@ func signalCredentialPreservationConfigInternal(config models.JSON, existingConf
return preserveConfig
}
+func emailCredentialPreservationConfigInternal(config models.JSON, existingConfig models.JSON) models.JSON {
+ preserveConfig := cloneNotificationConfigInternal(existingConfig)
+ if authMode, _ := config["authMode"].(string); authMode == string(models.EmailAuthModeNone) {
+ delete(preserveConfig, "smtpPassword")
+ }
+ return preserveConfig
+}
+
func encryptNotificationCredentialInternal(value string) (string, error) {
if value == "" {
return "", nil
diff --git a/backend/internal/services/notification_service_test.go b/backend/internal/services/notification_service_test.go
index 1a0f30997..a05869b73 100644
--- a/backend/internal/services/notification_service_test.go
+++ b/backend/internal/services/notification_service_test.go
@@ -577,6 +577,30 @@ func TestNotificationService_CreateOrUpdateSettingsPreservesStoredCredentialWhen
require.Equal(t, "initial-gotify-token", decrypted)
}
+func TestNotificationService_CreateOrUpdateSettingsClearsEmailPasswordWhenAuthModeNoneInternal(t *testing.T) {
+ ctx := context.Background()
+ db := setupNotificationTestDB(t)
+ svc := NewNotificationService(db, &config.Config{}, nil, nil)
+
+ _, err := svc.CreateOrUpdateSettings(ctx, models.NotificationProviderEmail, true, models.JSON{
+ "smtpHost": "smtp.example",
+ "smtpPassword": "stale-password",
+ "authMode": "auto",
+ })
+ require.NoError(t, err)
+
+ _, err = svc.CreateOrUpdateSettings(ctx, models.NotificationProviderEmail, true, models.JSON{
+ "smtpHost": "smtp.example",
+ "smtpPassword": "",
+ "authMode": string(models.EmailAuthModeNone),
+ })
+ require.NoError(t, err)
+
+ var stored models.NotificationSettings
+ require.NoError(t, db.WithContext(ctx).Where("provider = ?", models.NotificationProviderEmail).First(&stored).Error)
+ require.Empty(t, stored.Config["smtpPassword"])
+}
+
func TestNotificationService_CreateOrUpdateSettingsPreservesCredentialAcrossDisableInternal(t *testing.T) {
ctx := context.Background()
db := setupNotificationTestDB(t)
diff --git a/backend/pkg/utils/notifications/email_sender.go b/backend/pkg/utils/notifications/email_sender.go
index 774cef7f6..edcf5d55e 100644
--- a/backend/pkg/utils/notifications/email_sender.go
+++ b/backend/pkg/utils/notifications/email_sender.go
@@ -47,6 +47,8 @@ func smtpBuildOptionsFromContextInternal(ctx context.Context) smtpBuildOptions {
func smtpAuthTypeFromModeInternal(mode models.EmailAuthMode) mail.SMTPAuthType {
switch mode {
+ case models.EmailAuthModeNone:
+ return mail.SMTPAuthNoAuth
case models.EmailAuthModeAuto:
return mail.SMTPAuthAutoDiscover
case models.EmailAuthModePlain:
@@ -89,7 +91,7 @@ func buildMailClientInternal(config models.EmailConfig, options smtpBuildOptions
opts = append(opts, mail.WithTLSConfig(options.tlsConfig))
}
- if config.SMTPUsername != "" || config.SMTPPassword != "" {
+ if config.AuthMode != models.EmailAuthModeNone && config.SMTPUsername != "" && config.SMTPPassword != "" {
opts = append(opts,
mail.WithSMTPAuth(smtpAuthTypeFromModeInternal(config.AuthMode)),
mail.WithUsername(config.SMTPUsername),
diff --git a/backend/pkg/utils/notifications/email_sender_test.go b/backend/pkg/utils/notifications/email_sender_test.go
index cb2c7c1ff..0df7cf117 100644
--- a/backend/pkg/utils/notifications/email_sender_test.go
+++ b/backend/pkg/utils/notifications/email_sender_test.go
@@ -129,6 +129,27 @@ func TestSendEmailAuthLoginAgainstExchangeStyleServer(t *testing.T) {
assertCommandOrderInternal(t, server.Commands(), "EHLO", "STARTTLS", "EHLO", "AUTH", "MAIL", "RCPT", "DATA", "QUIT")
}
+func TestSendEmailStalePasswordWithoutUsernameSkipsAuth(t *testing.T) {
+ server := newSMTPTestServerInternal(t, false, nil)
+ defer server.Close()
+
+ config := models.EmailConfig{
+ SMTPHost: smtpTestHost,
+ SMTPPort: server.Port(),
+ SMTPPassword: "stale-password",
+ FromAddress: "[email protected]",
+ ToAddresses: []string{"[email protected]"},
+ TLSMode: models.EmailTLSModeNone,
+ AuthMode: models.EmailAuthModeAuto,
+ }
+
+ err := sendEmailInternal(context.Background(), config, "Arcane No-Auth Test", "<p>Test</p>", smtpBuildOptions{})
+ require.NoError(t, err)
+ require.NoError(t, server.Wait())
+
+ assert.NotContains(t, server.Commands(), "AUTH", "expected no AUTH attempt without complete credentials")
+}
+
func newSMTPTestServerInternal(t *testing.T, supportStartTLS bool, authMechanisms []string) *smtpTestServer {
t.Helper()
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 071e4f06d..5a8c3dde9 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -2547,8 +2547,9 @@
"notifications_email_tls_mode_description": "StartTLS (default) upgrades from plain connection. SSL/TLS uses encryption from start. None uses no encryption.",
"notifications_email_auth_mode_label": "Authentication Method",
"notifications_email_auth_mode_placeholder": "Select authentication method",
- "notifications_email_auth_mode_description": "Auto-detect (default) picks the strongest method the server advertises. Pick LOGIN for Microsoft Exchange or Office 365 if auto-detect fails.",
+ "notifications_email_auth_mode_description": "Auto-detect (default) picks the strongest method the server advertises. Pick LOGIN for Microsoft Exchange or Office 365 if auto-detect fails. None disables SMTP authentication and clears any saved password when you save.",
"notifications_email_auth_mode_option_auto": "Auto-detect (recommended)",
+ "notifications_email_auth_mode_option_none": "None (no authentication)",
"notifications_email_test_simple": "Simple Test Notification",
"notifications_email_test_image_update": "Image Update Notification",
"notifications_email_test_batch_image_update": "Batch Image Updates Notification",
diff --git a/frontend/src/lib/types/notifications.ts b/frontend/src/lib/types/notifications.ts
index b7c880d9c..114391395 100644
--- a/frontend/src/lib/types/notifications.ts
+++ b/frontend/src/lib/types/notifications.ts
@@ -3,7 +3,7 @@
export type NotificationProvider =
'discord' | 'email' | 'telegram' | 'signal' | 'slack' | 'ntfy' | 'pushover' | 'gotify' | 'matrix' | 'generic';
export type EmailTLSMode = 'none' | 'starttls' | 'ssl';
-export type EmailAuthMode = 'auto' | 'plain' | 'login' | 'crammd5';
+export type EmailAuthMode = 'none' | 'auto' | 'plain' | 'login' | 'crammd5';
export interface NotificationSettings {
provider: NotificationProvider;
diff --git a/frontend/src/routes/(app)/settings/notifications/providers/BuiltInProviderForm.svelte b/frontend/src/routes/(app)/settings/notifications/providers/BuiltInProviderForm.svelte
index 1f317b5f0..49331e6df 100644
--- a/frontend/src/routes/(app)/settings/notifications/providers/BuiltInProviderForm.svelte
+++ b/frontend/src/routes/(app)/settings/notifications/providers/BuiltInProviderForm.svelte
@@ -128,7 +128,7 @@
fromAddress: z.string(),
toAddresses: z.string(),
tlsMode: z.enum(['none', 'starttls', 'ssl']),
- authMode: z.enum(['auto', 'plain', 'login', 'crammd5']),
+ authMode: z.enum(['none', 'auto', 'plain', 'login', 'crammd5']),
...eventSubscriptionSchemaFields
})
.superRefine((d, ctx) => {
@@ -478,6 +478,7 @@
description: m.notifications_email_auth_mode_description(),
options: [
{ value: 'auto', label: m.notifications_email_auth_mode_option_auto() },
+ { value: 'none', label: m.notifications_email_auth_mode_option_none() },
{ value: 'plain', label: 'PLAIN' },
{ value: 'login', label: 'LOGIN' },
{ value: 'crammd5', label: 'CRAM-MD5' }