@@ -137,14 +137,20 @@ func (s *SMTPHandler) dispatch(subject, htmlBody, plainBody, to string) Delivery
137
137
138
138
// Check for authentication capabilities.
139
139
if ok , avail := c .Extension ("AUTH" ); ok {
140
- // Ensure the auth mechanisms available are ones we can use.
140
+ // Ensure the auth mechanisms available are ones we can use, and create a SASL client .
141
141
auth , err := s .auth (ctx , avail )
142
142
if err != nil {
143
143
return true , xerrors .Errorf ("determine auth mechanism: %w" , err )
144
144
}
145
145
146
- // If so, use the auth mechanism to authenticate.
147
- if auth != nil {
146
+ if auth == nil {
147
+ // If we get here, no SASL client (which handles authentication) was returned.
148
+ // This is expected if auth is supported by the smarthost BUT no authentication details were configured.
149
+ s .noAuthWarnOnce .Do (func () {
150
+ s .log .Warn (ctx , "skipping auth; no authentication client created" )
151
+ })
152
+ } else {
153
+ // We have a SASL client, use it to authenticate.
148
154
if err := c .Auth (auth ); err != nil {
149
155
return true , xerrors .Errorf ("%T auth: %w" , auth , err )
150
156
}
@@ -434,9 +440,6 @@ func (s *SMTPHandler) auth(ctx context.Context, mechs string) (sasl.Client, erro
434
440
435
441
// All auth mechanisms require username, so if one is not defined then don't return an auth client.
436
442
if username == "" {
437
- s .noAuthWarnOnce .Do (func () {
438
- s .log .Warn (ctx , "skipping auth; no username configured" , slog .F ("support_mechanisms" , mechs ))
439
- })
440
443
// nolint:nilnil // This is a valid response.
441
444
return nil , nil
442
445
}
0 commit comments