MX record lookup with more than two MX (unreachable) records

Issue Description

Only the first two MX records seem to be tried during sending

Expected Behavior

TLS reports are successfully sent during a test with https://email-security-scans.org
All MX records should be tried in order of the priority, not only the first two.

Actual Behavior

Email to
tlsrpt@dzifx5ywhk5qte8ow8ne1f77h9xueo.uniq.measurement.email-security-scans.org
is queued in the outgoing queue until expiry.

The MX discovery from stalwart (according to admin/Management/x:Trace/OutboundDelivery) lists only the first two MX records:
dzifx5ywhk5qte8ow8ne1f77h9xueo.uzone.measurement.email-security-scans.org and dzifx5ywhk5qte8ow8ne1f77h9xueo.umx.v6only.measurement.email-security-scans.org - both of them are disabled by design.

The third one is not used:

delv -t MX dzifx5ywhk5qte8ow8ne1f77h9xueo.uniq.measurement.email-security-scans.org       
; fully validated
dzifx5ywhk5qte8ow8ne1f77h9xueo.uniq.measurement.email-security-scans.org. 273 IN MX 10 dzifx5ywhk5qte8ow8ne1f77h9xueo.uzone.measurement.email-security-scans.org.
dzifx5ywhk5qte8ow8ne1f77h9xueo.uniq.measurement.email-security-scans.org. 273 IN MX 20 dzifx5ywhk5qte8ow8ne1f77h9xueo.umx.v6only.measurement.email-security-scans.org.
dzifx5ywhk5qte8ow8ne1f77h9xueo.uniq.measurement.email-security-scans.org. 273 IN MX 50 mail.measurement.email-security-scans.org.

After talking to one of the maintainers of the email-security-scans.org test-suite, I got the following response:

i think this is a stalwart bug; The zone for receiving TLS-RPT has
three MX, of which only the lowest priority MX is actually deliverable.

It seems like stalwart is aborting after two attempts; You are the
second one writing me about this.

Might be worthwhile to file a bug there.

Reproduction Steps

  1. Start test via https://email-security-scans.org.
  2. Wait until TLS-reports are scheduled for sending.
  3. See the unsuccessful retries in admin/Management/x:Trace/OutboundDelivery.

Stalwart Version

v1.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

Filesystem

Search Engine

Internal

Directory Backend

Internal

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

This is a configured limit, not a bug. A new installation’s mx route sets maxMxHosts to 2. Each delivery attempt tries only that many MX hosts, taking the lowest preference values first. With a limit of 2, a domain’s third and later MX hosts are never tried. That matches what you see: the two unreachable hosts (priority 10 and 20) use up the limit, so mail.measurement.email-security-scans.org (priority 50) is never contacted.

To fix it, raise maxMxHosts on your mx route to 3 or more. You can do this in the WebUI under the MTA routes settings. The route object looks like this:

{
  "@type": "Mx",
  "name": "mx",
  "maxMxHosts": 5,
  "maxMultihomed": 2,
  "ipLookupStrategy": "v4ThenV6"
}

Keep your existing values for the other fields. The schema reference lists a default of 5 for maxMxHosts, but the docs say the initial mx route is created with 2. Check what your route currently has.

Docs:

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.