Skip to content

Commit f7fcaf9

Browse files
committed
Be more explicit about no auth
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent da550f4 commit f7fcaf9

File tree

1 file changed

+9
-6
lines changed
  • coderd/notifications/dispatch

1 file changed

+9
-6
lines changed

coderd/notifications/dispatch/smtp.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,20 @@ func (s *SMTPHandler) dispatch(subject, htmlBody, plainBody, to string) Delivery
137137

138138
// Check for authentication capabilities.
139139
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.
141141
auth, err := s.auth(ctx, avail)
142142
if err != nil {
143143
return true, xerrors.Errorf("determine auth mechanism: %w", err)
144144
}
145145

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.
148154
if err := c.Auth(auth); err != nil {
149155
return true, xerrors.Errorf("%T auth: %w", auth, err)
150156
}
@@ -434,9 +440,6 @@ func (s *SMTPHandler) auth(ctx context.Context, mechs string) (sasl.Client, erro
434440

435441
// All auth mechanisms require username, so if one is not defined then don't return an auth client.
436442
if username == "" {
437-
s.noAuthWarnOnce.Do(func() {
438-
s.log.Warn(ctx, "skipping auth; no username configured", slog.F("support_mechanisms", mechs))
439-
})
440443
// nolint:nilnil // This is a valid response.
441444
return nil, nil
442445
}

0 commit comments

Comments
 (0)