Your question
Hi everyone,
I am seeking help regarding a persistent issue where my mail server IP gets repeatedly listed on Spamhaus SBL due to HELO localhost, even though Stalwart seems to be properly configured.
Environment & Architecture:
Server OS: Ubuntu/Linux (running behind NAT / internal IP 10.0.6.x)
Public Sending IP: 198.51.100.xxx
Mail Server FQDN: mail200[dot]example[dot]com
Reverse DNS (PTR): 198.51.100.xxx → mail200[dot]example[dot]com (Fully verified with matching forward A record)
Current Stalwart Configuration:
Outbound EHLO: Configured under Source IP Addresses:
Source IP: 10.0.6.x
EHLO Hostname: mail200[dot]example[dot]com
Inbound Banner: Connecting to port 25 returns: 220 mail200[dot]example[dot]com Stalwart ESMTP at your service
Live Test Results: When sending a test email to Gmail, the headers confirm valid FCrDNS, SPF, DKIM, and DMARC:
Received: from mail200[dot]example[dot]com (mail200[dot]example[dot]com. [198.51.100.xxx])
SPF: PASS with IP 198.51.100.xxx
DKIM: PASS with domain example[dot]com
DMARC: PASS
The Issue:
After getting delisted from Spamhaus, the IP was listed again the next day with the exact same reason:
HELO check failed: Not a valid hostname. Most recently seen HELO: localhost
Spamhaus suggested:
Restricting outbound port 25 so only the Stalwart mail server process can use it.
Checking for potential compromise/unauthorized outgoing connections.
Questions for the Community:
Under what conditions could Stalwart send an outbound HELO/EHLO localhost instead of the configured hostname? (e.g., DNS lookup timeouts, IPv6 fallbacks, internal delivery retries, DSN/NDR bounces, or unauthenticated local submissions?)
Does the Source IP → EHLO Hostname override apply to all outbound traffic, or is there a global fallback setting that I might have missed (e.g., in server.hostname or outbound client pool)?
How can I best log or trace all outbound SMTP handshakes made by Stalwart to identify what exact connection used localhost?
Any advice or insights would be greatly appreciated. Thanks!
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
The key fallback chain is: EHLO hostname → connection-strategy’s ehloHostname (or per-source-IP override) → if unset, the global defaultHostname on SystemSettings → if that’s unset too, the hostname reported by the OS. If your container/VM’s OS-level hostname is literally localhost (common on NAT’d/containerized hosts where the hostname was never set), and either defaultHostname is empty or the specific delivery doesn’t go through the connection strategy where you set the per-source override, Stalwart will advertise localhost in the outbound EHLO.
To your specific questions:
-
When could Stalwart send EHLO localhost? Not from DNS timeouts or IPv6 fallback per se, but from falling through the hostname-resolution chain above. A likely cause: your ehloHostname override is only set on a specific sourceIp entry inside one connection strategy. If some outbound traffic (e.g. retries, DSN bounces, or mail matched by a different connection expression in your MtaOutboundStrategy) is routed through a different/default connection strategy that has no ehloHostname set, it falls back to defaultHostname, and if that’s also unset, to the OS hostname. Check what the container/host actually reports with hostname — if it prints localhost, that’s almost certainly your leak path.
-
Does the source-IP → EHLO override apply to all outbound traffic? No. It only applies when that specific connection strategy (and, for per-IP overrides, that specific sourceIp entry) is selected for a given delivery via the connection expression on MtaOutboundStrategy. If other deliveries resolve to a different strategy or the expression falls through to a default with no override, they’ll use the strategy-wide ehloHostname, and failing that, defaultHostname. Make sure defaultHostname is explicitly set on SystemSettings as a backstop, not left to the OS hostname.
-
Tracing outbound handshakes: Stalwart emits structured events per delivery attempt, including delivery.ehlo (EHLO sent), delivery.missing-outbound-hostname (warns when no outbound EHLO hostname is configured at all), and delivery.raw-output/delivery.raw-input at trace level for the full SMTP dialogue. Raising logging to include these events will show you exactly what hostname is sent on every connection and let you correlate it with the triggering message.
Reference: Connection strategy / EHLO hostname, Server hostname, Delivery events reference.
This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.
However, defaulthostname has already been set from the beginning.
# docker exec -it stalwart-aqsntoh5rpoxynleznvuqvvi hostname
1a911aac886c
the linux hostname is not localhost
Stalwart won’t send HELO localhost with your setup. The outbound EHLO name is taken from the source IP’s EHLO hostname, then the connection strategy’s, and finally defaultHostname, and that applies to every remote delivery, DSNs and reports included (delivery.rs). With defaultHostname set there’s no path that ends at localhost, which matches what Gmail recorded in your Received header.
So the connection Spamhaus saw almost certainly came from something else that leaves through the same public IP. Behind NAT that’s every machine in 10.0.6.x that gets masqueraded to 198.51.100.xxx, and every other container on the Docker host. A web app calling mail() or a compromised container talking SMTP directly to the internet is the usual culprit, and Spamhaus’s suggestion is the right one: allow outbound port 25 at the NAT/firewall only from the Stalwart host, and on the Docker host only from the Stalwart container (the DOCKER-USER iptables chain is the place for that). Logging dropped port 25 packets there will also tell you which machine or container is trying.
On the Stalwart side, delivery.connect and delivery.ehlo are logged at debug level for every outbound session, and delivery.raw-output at trace level shows the exact EHLO line sent (events reference). If you’d like proof that Stalwart isn’t the source, compare those against the time Spamhaus gives for the listing.