From 46dfd926d9ab72e270bc428b0820d4ae97febd70 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Thu, 26 Jun 2025 15:39:10 +0200 Subject: [PATCH] Fix message delivery failure error reason --- crates/smtp/src/outbound/delivery.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/smtp/src/outbound/delivery.rs b/crates/smtp/src/outbound/delivery.rs index 8159beb6..a4fb54c6 100644 --- a/crates/smtp/src/outbound/delivery.rs +++ b/crates/smtp/src/outbound/delivery.rs @@ -1380,27 +1380,33 @@ impl Message { std::mem::replace(&mut domain.status, Status::Scheduled).into_permanent(); } Status::Scheduled if domain.expires <= now => { + let mut had_attempts = false; + for rcpt in &mut self.recipients { + if rcpt.domain_idx == idx as u32 { + had_attempts |= !matches!(rcpt.status, Status::Scheduled); + rcpt.status = std::mem::replace(&mut rcpt.status, Status::Scheduled) + .into_permanent(); + } + } + + let reason = if had_attempts { + "Message delivery failed." + } else { + "Message expired without any delivery attempts made." + }; + trc::event!( Delivery(DeliveryEvent::Failed), SpanId = self.span_id, Domain = domain.domain.clone(), - Reason = "Message expired without any delivery attempts made.", + Reason = reason, Details = trc::Value::Timestamp(now), Expires = trc::Value::Timestamp(domain.expires), NextRetry = trc::Value::Timestamp(domain.retry.due), NextDsn = trc::Value::Timestamp(domain.notify.due), ); - for rcpt in &mut self.recipients { - if rcpt.domain_idx == idx as u32 { - rcpt.status = std::mem::replace(&mut rcpt.status, Status::Scheduled) - .into_permanent(); - } - } - - domain.status = Status::PermanentFailure(Error::Io( - "Message expired without any delivery attempts made.".into(), - )); + domain.status = Status::PermanentFailure(Error::Io(reason.into())); } Status::Completed(_) | Status::PermanentFailure(_) => (), _ => {