Skip to content

Commit 401d862

Browse files
mail: Rename RecoverableSMTPError to BadAddressSMTPError (letsencrypt#5479)
Rename `RecoverableSMTPError` to `BadAddressSMTPError`. The former implies that an operation resulting in this error can be retried.
1 parent 205223a commit 401d862

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

cmd/notify-mailer/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ func (m *mailer) run() error {
170170

171171
err := m.mailer.SendMail([]string{address}, m.subject, messageBody.String())
172172
if err != nil {
173-
var recoverableSMTPErr bmail.RecoverableSMTPError
174-
if errors.As(err, &recoverableSMTPErr) {
175-
m.log.Errf("Address %q was rejected by the server due to: %s", address, err)
173+
var badAddrErr bmail.BadAddressSMTPError
174+
if errors.As(err, &badAddrErr) {
175+
m.log.Errf("address %q was rejected by server: %s", address, err)
176176
continue
177177
}
178178
return fmt.Errorf("while sending mail (%d) of (%d) to address %q: %s",

mail/mailer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,22 @@ func (m *MailerImpl) sendOne(to []string, subject, msg string) error {
306306
return nil
307307
}
308308

309-
// RecoverableSMTPError is returned by SendMail when the server rejects a message
309+
// BadAddressSMTPError is returned by SendMail when the server rejects a message
310310
// but for a reason that doesn't prevent us from continuing to send mail. The
311311
// error message contains the error code and the error message returned from the
312312
// server.
313-
type RecoverableSMTPError struct {
313+
type BadAddressSMTPError struct {
314314
Message string
315315
}
316316

317-
func (e RecoverableSMTPError) Error() string {
317+
func (e BadAddressSMTPError) Error() string {
318318
return e.Message
319319
}
320320

321321
// Based on reading of various SMTP documents these are a handful
322322
// of errors we are likely to be able to continue sending mail after
323323
// receiving. The majority of these errors boil down to 'bad address'.
324-
var recoverableErrorCodes = map[int]bool{
324+
var badAddressErrorCodes = map[int]bool{
325325
401: true, // Invalid recipient
326326
422: true, // Recipient mailbox is full
327327
441: true, // Recipient server is not responding
@@ -377,9 +377,9 @@ func (m *MailerImpl) SendMail(to []string, subject, msg string) error {
377377
m.reconnect()
378378
// After reconnecting, loop around and try `sendOne` again.
379379
continue
380-
} else if errors.As(err, &protoErr) && recoverableErrorCodes[protoErr.Code] {
380+
} else if errors.As(err, &protoErr) && badAddressErrorCodes[protoErr.Code] {
381381
m.sendMailAttempts.WithLabelValues("failure", fmt.Sprintf("SMTP %d", protoErr.Code)).Inc()
382-
return RecoverableSMTPError{fmt.Sprintf("%d: %s", protoErr.Code, protoErr.Msg)}
382+
return BadAddressSMTPError{fmt.Sprintf("%d: %s", protoErr.Code, protoErr.Msg)}
383383
} else {
384384
// If it wasn't an EOF error or a recoverable SMTP error it is unexpected and we
385385
// return from SendMail() with the error

mail/mailer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,12 @@ func TestBadEmailError(t *testing.T) {
359359
err = m.SendMail([]string{"hi@bye.com"}, "You are already a winner!", "Just kidding")
360360
// We expect there to be an error
361361
if err == nil {
362-
t.Errorf("Expected SendMail() to return an RecoverableSMTPError, got nil")
362+
t.Errorf("Expected SendMail() to return an BadAddressSMTPError, got nil")
363363
}
364364
expected := "401: 4.1.3 Bad recipient address syntax"
365-
var rcptErr RecoverableSMTPError
366-
test.AssertErrorWraps(t, err, &rcptErr)
367-
test.AssertEquals(t, rcptErr.Message, expected)
365+
var badAddrErr BadAddressSMTPError
366+
test.AssertErrorWraps(t, err, &badAddrErr)
367+
test.AssertEquals(t, badAddrErr.Message, expected)
368368
}
369369

370370
func TestReconnectSMTP421(t *testing.T) {

0 commit comments

Comments
 (0)