Issue Description
Cannot use external DNS. SMTP reply slow (DNS timeout).
Expected Behavior
I would like this to work reliably and fast.
Actual Behavior
SMTP test on Network Tools: DNS,IP,Email for my domain says SMTP Transaction Time is wrong, full 5s delay before SMTP answers relay not allowed.
Tried changing DNS resolver from system to any other, but then email delivery test says it cannot look up MX records at all.
DNS on host works normally and fast.
Stalwart Version
v0.16.x
Installation Method
Binary (Linux)
Database Backend
RocksDB
Blob Storage
RocksDB
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
There are two separate issues here, and the DNS resolver docs explain both clearly.
Issue 1: 5-second SMTP greeting delay
The default DNS resolver timeout is 5 seconds and the default attempts is 2. If Stalwart’s system resolver is having trouble (e.g. doing a PTR/rDNS lookup on the connecting IP during the SMTP greeting), it will wait up to 5 seconds before timing out. This matches exactly the delay you’re seeing. You can reduce timeout (e.g. to "2s") in the DnsResolver settings in the WebUI under Settings > Network > DNS > DNS Resolver.
Issue 2: Custom/external DNS can’t resolve MX records
A key note from the docs: most public DNSBL services do not accept queries from public open resolvers, but this also applies in reverse for some setups. If you switch to an external resolver (Cloudflare, Google, etc.) and MX lookups fail, it could be a network-level issue – specifically, many VPS/hosting providers block or intercept outbound UDP port 53. Try using the Custom variant with "protocol": "tcp" or "tls" instead of the default udp, pointing at a reliable upstream resolver (e.g. 8.8.8.8).
To configure this in the WebUI (Settings > Network > DNS > DNS Resolver), or via the API, use a config like:
{
"@type": "Custom",
"servers": [
{"address": "8.8.8.8", "port": 53, "protocol": "tcp"},
{"address": "1.1.1.1", "port": 53, "protocol": "tcp"}
],
"timeout": "2s",
"attempts": 2
}
Summary of recommended steps:
- Try switching from
System to Custom with TCP protocol to work around any UDP port 53 blocking.
- Lower
timeout to "2s" to reduce the SMTP greeting delay.
- If DNSBL lookups are in use, be aware those may need to stay on the system resolver.
Docs reference: DNS Resolver configuration
This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.
Looks like changing timeout isn’t affecting the 5s wasted to get 550 5.1.2 Relay not allowed. [5243 ms] from MX test.
Oh, my. It’s Stalwart’s own wait after error on RCPT TO. Case closed. As for DNS issues, I’ll keep system resolver then.