PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
FIX (email): Add login auth in case if plain fails
Rostislav Dugin14700130b728
diff --git a/backend/internal/features/notifiers/models/email_notifier/dto.go b/backend/internal/features/notifiers/models/email_notifier/dto.gonew file mode 100644index 00000000..d9325f77--- /dev/null+++ b/backend/internal/features/notifiers/models/email_notifier/dto.go@@ -0,0 +1,28 @@+package email_notifier++import (+ "errors"+ "net/smtp"+)++type loginAuth struct {+ username, password string+}++func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {+ return "LOGIN", []byte{}, nil+}++func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {+ if more {+ switch string(fromServer) {+ case "Username:":+ return []byte(a.username), nil+ case "Password:":+ return []byte(a.password), nil+ default:+ return nil, errors.New("unknown LOGIN challenge: " + string(fromServer))+ }+ }+ return nil, nil+}diff --git a/backend/internal/features/notifiers/models/email_notifier/model.go b/backend/internal/features/notifiers/models/email_notifier/model.goindex 9d0dd1d8..89b28f32 100644--- a/backend/internal/features/notifiers/models/email_notifier/model.go+++ b/backend/internal/features/notifiers/models/email_notifier/model.go@@ -132,9 +132,8 @@ func (e *EmailNotifier) Send(// Set up authentication only if credentials are providedif isAuthRequired {- auth := smtp.PlainAuth("", e.SMTPUser, smtpPassword, e.SMTPHost)- if err := client.Auth(auth); err != nil {- return fmt.Errorf("SMTP authentication failed: %w", err)+ if err := e.authenticate(client, smtpPassword); err != nil {+ return err}}@@ -195,9 +194,8 @@ func (e *EmailNotifier) Send(// Authenticate only if credentials are providedif isAuthRequired {- auth := smtp.PlainAuth("", e.SMTPUser, smtpPassword, e.SMTPHost)- if err := client.Auth(auth); err != nil {- return fmt.Errorf("SMTP authentication failed: %w", err)+ if err := e.authenticate(client, smtpPassword); err != nil {+ return err}}@@ -256,3 +254,19 @@ func (e *EmailNotifier) EncryptSensitiveData(encryptor encryption.FieldEncryptor}return nil}++func (e *EmailNotifier) authenticate(client *smtp.Client, password string) error {+ // Try PLAIN auth first (most common)+ plainAuth := smtp.PlainAuth("", e.SMTPUser, password, e.SMTPHost)+ if err := client.Auth(plainAuth); err == nil {+ return nil+ }++ // If PLAIN fails, try LOGIN auth (required by Office 365 and some providers)+ loginAuth := &loginAuth{e.SMTPUser, password}+ if err := client.Auth(loginAuth); err != nil {+ return fmt.Errorf("SMTP authentication failed: %w", err)+ }++ return nil+}