diff --git a/queue/direct.go b/queue/direct.go index 3e2788c..0bebaec 100644 --- a/queue/direct.go +++ b/queue/direct.go @@ -303,7 +303,7 @@ func deliverDirect(qlog mlog.Log, resolver dns.Resolver, dialer smtpclient.Diale for i, mr := range result.delivered { mqlog := nqlog.With(slog.Int64("msgid", mr.msg.ID), slog.Any("recipient", mr.msg.Recipient())) mqlog.Info("delivered from queue") - mr.msg.markResult(0, "", "", true) + mr.msg.markResult(mr.resp.Code, mr.resp.Secode, "", true) delMsgs[i] = *mr.msg } if len(delMsgs) > 0 { @@ -745,6 +745,7 @@ func deliverHost(log mlog.Log, resolver dns.Resolver, dialer smtpclient.Dialer, } else if i > 0 && (resps[i].Code == smtp.C452StorageFull || resps[i].Code == smtp.C552MailboxFull) { ntodo = append(ntodo, mr) } else if resps[i].Code == smtp.C250Completed { + mr.resp = resps[i] delivered = append(delivered, mr) } else { failed = append(failed, mr) diff --git a/queue/queue.go b/queue/queue.go index 76b9af6..0a987be 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -206,7 +206,7 @@ func (m *Msg) markResult(code int, secode string, errmsg string, success bool) { result.Code = code result.Secode = secode result.Error = errmsg - result.Success = false + result.Success = success } // LastResult returns the last result entry, or an empty result. diff --git a/queue/queue_test.go b/queue/queue_test.go index 3474ee8..974dea4 100644 --- a/queue/queue_test.go +++ b/queue/queue_test.go @@ -1027,6 +1027,10 @@ func TestRetiredHooks(t *testing.T) { if expResult.Secode != "" { ecode = fmt.Sprintf("%d.%s", expResult.Code/100, expResult.Secode) } + var code int // Only set for errors. + if expResult.Code != 250 { + code = expResult.Code + } expOut := webhook.Outgoing{ Event: webhook.OutgoingEvent(expEvent), Suppressing: expSuppressing, @@ -1034,7 +1038,7 @@ func TestRetiredHooks(t *testing.T) { FromID: mr.FromID, MessageID: mr.MessageID, Subject: mr.Subject, - SMTPCode: expResult.Code, + SMTPCode: code, SMTPEnhancedCode: ecode, Extra: mr.Extra, } @@ -1130,7 +1134,7 @@ func TestRetiredHooks(t *testing.T) { } testAction("mjl", makeLaunchAction(smtpAccept), nil, "", false) - testAction("retired", makeLaunchAction(smtpAccept), &MsgResult{}, string(webhook.EventDelivered), false) + testAction("retired", makeLaunchAction(smtpAccept), &MsgResult{Code: 250, Success: true}, string(webhook.EventDelivered), false) // 554 is generic, doesn't immediately cause suppression. testAction("mjl", makeLaunchAction(smtpReject(554)), nil, "", false) testAction("retired", makeLaunchAction(smtpReject(554)), &MsgResult{Code: 554, Secode: "1.0", Error: "nonempty"}, string(webhook.EventFailed), false) diff --git a/queue/submit.go b/queue/submit.go index a79c7ab..f6bdbbe 100644 --- a/queue/submit.go +++ b/queue/submit.go @@ -264,7 +264,8 @@ func processDeliveries(qlog mlog.Log, m0 *Msg, msgs []*Msg, remoteAddr string, r failMsgsDB(qmlog, []*Msg{m}, m0.DialedIPs, backoff, remoteMTA, err) failed++ } else { - m.markResult(0, "", "", true) + resp := rcptErrs[i] + m.markResult(resp.Code, resp.Secode, "", true) delMsgs = append(delMsgs, *m) qmlog.Info("delivered from queue with transport") delivered++