Do not auth unless we have something to auth with

This commit is contained in:
Nicolai Langfeldt
2025-04-25 12:48:59 +02:00
parent 5d8c9cef9a
commit 118f7b698f

View File

@ -105,14 +105,14 @@ func handshake(client *smtp.Client, config *relayConfig, tlsConfig *tls.Config)
} }
var auth smtp.Auth var auth smtp.Auth = nil
if config.LoginAuthType { if config.LoginAuthType {
auth = LoginAuth(config.Username, config.Password) auth = LoginAuth(config.Username, config.Password)
} else { } else if config.Username != "" {
auth = smtp.PlainAuth("", config.Username, config.Password, config.Server) auth = smtp.PlainAuth("", config.Username, config.Password, config.Server)
} }
if err := client.Auth(auth); err != nil { if auth != nil && err := client.Auth(auth); err != nil {
return errors.Wrap(err, "auth error") return errors.Wrap(err, "auth error")
} }
return nil return nil