Practical guide: fix high SMTP latency in Postfix on a VPS and prevent email queue buildup
By Kevin Marcondes · Published on · 7 min read
Looking to fix high SMTP latency in Postfix on a VPS and avoid email queues piling up? This guide shows how to pinpoint bottlenecks using logs, DNS and network tests, apply safe Postfix adjustments, and drain the queue without losing messages. Includes practical commands, root-cause indicators and monitoring tips to keep outbound mail stable.
Why SMTP becomes slow on a VPS and queues grow
SMTP latency usually stems from three groups: slow DNS/network, slow TLS handshakes, and local Postfix limits or congestion. On VPSs, CPU steal spikes, slow storage and port-25 filtering by the provider can make things worse.
When the queue grows it’s not just volume. Many messages become “deferred” while waiting for retries, which raises average delivery time and increases Postfix process usage.
How to detect latency and where the bottleneck is
Map symptoms and measure timings. Combine queue state, logs and connection tests to distinguish local delays (processes and DNS) from waits at the destination server.
Use the table below as a quick guide, then run the commands to confirm.
| Signal | Command/where to check | What to look for |
|---|---|---|
| Queue growing | postqueue -p / mailq | Total count and deferred messages |
| Repeated redeliveries | /var/log/mail.log | status=deferred to the same destination (MX) |
| Slow handshake (TLS) | STARTTLS test on the destination | Time until 220/250 banner and handshake completion |
| Slow DNS resolution | Logs and network tools | Time to resolve domains' MX/A/AAAA |
# 1) Fila e resumo
postqueue -p
# Contar quantas estão adiadas (deferred)
grep -E "status=deferred" -c /var/log/mail.log
# 2) Handshake STARTTLS no destino (substitua mx.exemplo.com)
# Mede tempo do handshake e banners
TIMEFORMAT='elapsed %3R s'; time \
openssl s_client -starttls smtp -connect mx.exemplo.com:25 -crlf </dev/null
# 3) Parâmetros ativos do Postfix (para revisão)
postconf -n
Common causes and how to confirm them
Check the items below first — confirm each hypothesis before changing configuration.
If latency affects only a few domains, it could be greylisting, IP reputation, long DNS TTLs or a slow specific MX. If it affects all destinations, focus on local DNS, Postfix process limits and network bottlenecks.
- No local DNS cache: every MX/A/AAAA lookup is slow. Confirm with long resolve times between attempts in the logs.
- Slow TLS handshake: low entropy, high CPU or packet loss. Measure with the STARTTLS test.
- Low Postfix limits: too few processes or low per-destination concurrency. Inspect output of postconf -n.
- CPU steal and slow disk on the VPS: host spikes can delay queue processing. Monitor with top/vmstat/iostat.
- Provider blocks/restrictions: port 25 filtering or outbound throttling.
Postfix adjustments that often unblock deliveries
Adjust cautiously and validate impact. Don’t increase everything at once. Start with process limits, SMTP timeouts and connection reuse. Changes require a Postfix reload.
Values below are examples; tune them to your CPU/RAM, volume and destination profile. Monitor the queue and logs after each change.
# /etc/postfix/main.cf — exemplos (ajuste aos seus recursos)
# Mais processos para lidar com fila (cautela em VPS pequena)
default_process_limit = 150
# Concorrência por destino MX (evita fila parada num único host)
smtp_destination_concurrency_limit = 5
# Reutilizar conexões para reduzir handshakes
smtp_connection_cache_on_demand = yes
smtp_connection_cache_time_limit = 600s
# Timeouts SMTP equilibrados (evitam esperar indefinidamente)
smtp_connect_timeout = 30s
smtp_helo_timeout = 60s
smtp_mail_timeout = 60s
smtp_rcpt_timeout = 60s
smtp_data_init_timeout = 120s
smtp_data_xfer_timeout = 180s
smtp_data_done_timeout = 120s
# Preferir IPv4 se o IPv6 da VPS não estiver estável
smtp_address_preference = ipv4
# Após editar:
# systemctl reload postfix
DNS, TLS and network: reduce handshake time
Run a local caching resolver (e.g., systemd-resolved or unbound). That cuts repeated MX/A/AAAA lookups. Point /etc/resolv.conf to the local cache.
Ensure correct rDNS for your IP and publish SPF/DKIM/DMARC policies. Besides improving deliverability, they reduce deferrals with some providers. See the step-by-step in the guide: SPF, DKIM & DMARC for Postfix — Guide.
If your VPS IPv6 is unstable, prefer IPv4 (parameter shown above). Keep TLS libraries up to date to benefit from faster ciphers. Monitor packet loss and latency with periodic tests.
Large queue: strategies to safely release it
Fix the root cause before forcing the queue. Then requeue gradually. Do not delete messages unless you’re certain about destinations and impacts.
You can requeue, release messages on hold and force a queue flush. Work in short windows and follow logs in real time.
# Ver fila
a) postqueue -p
# Reencaminhar tudo (requeue)
b) postsuper -r ALL
# Liberar mensagens em HOLD (se houver)
c) postsuper -H ALL
# Forçar tentativa imediata (flush)
d) postqueue -f
# Opcional: pausar envios para ajuste (curto período)
# systemctl stop postfix && (ajustes) && systemctl start postfix
# Acompanhar logs
tail -f /var/log/mail.log
Monitor so it doesn't happen again
Monitor total queue, percentage of deferred messages, handshake times and errors by destination. Simple alerts help you act before messages pile up.
Centralize logs to make correlation with network and app events easier. A lightweight collection and dashboard stack works well on a VPS. For sustainable handling of SMTP latency and queue buildup, continuous monitoring is essential.
If you want quick instrumentation, see the Prometheus/Grafana guide: Guide: Prometheus & Grafana with Docker Compose on a VPS. For centralized logs, check Fluentd + Elasticsearch: PHP logs on a VPS (guide). And for server basics, use the VPS Linux security checklist.
- Minimum metrics: queue size, deferred per MX, average send time.
- Alerts: queue > defined threshold for X minutes; spikes in timeouts/connections.
- Routine: weekly review of summarized logs (pflogsumm or equivalent).
Frequently asked questions
How to quickly see if Postfix's queue is accumulating?
Use postqueue -p (or mailq) to list the queue and check totals. In logs, look for status=deferred to find delayed messages. If deferred counts keep growing and don’t return to normal, you likely have a network, DNS, TLS issue or Postfix limits causing the backlog.
Which Postfix settings should I adjust first?
Start with default_process_limit, smtp_destination_concurrency_limit and SMTP timeouts (smtp_connect_timeout, smtp_helo_timeout, smtp_mail_timeout, smtp_rcpt_timeout). Enable connection caching with smtp_connection_cache_on_demand and smtp_connection_cache_time_limit. Apply changes gradually and monitor the queue.
Latency only happens with some mail providers. What could that be?
Possible causes include greylisting, the sending IP’s reputation, a slow specific MX or no DNS caching. Check rDNS and SPF/DKIM/DMARC, measure the handshake with STARTTLS, and see if the same MX appears repeatedly in status=deferred entries.
Does using a relayhost help reduce the queue?
In some cases, yes. A reliable relayhost centralizes deliveries and can reduce deferrals, but it adds dependency and new limits. If you use one, authenticate via SASL and monitor the relay’s quotas and responses to avoid creating another queue at the relay.
Can I delete the queue to ‘clear things out’?
Not recommended. You risk losing legitimate messages. Prefer fixing the root cause, requeueing (postsuper -r ALL) and releasing gradually. Delete only messages that are confirmed irrelevant or invalid and with agreement from system owners.
Will improving DNS really help SMTP latency?
Yes. A local caching resolver reduces MX/A/AAAA lookup time, especially when sending to many domains. On a VPS this typically yields noticeable improvements by avoiding repeated external DNS latency on every delivery.
Want to stabilize your Postfix SMTP deliveries?
Targeted diagnostics, safe adjustments and a monitoring plan for your VPS. Let's discuss your setup and next steps.
Talk about Postfix & SMTPSee also
- Intermittent 502 Bad Gateway in Docker Compose with Nginx & PHP‑FPM: how to diagnose and fix timeouts and connection overloads
- How to diagnose and capture packets for intermittent network issues between Docker containers on Debian
- How to detect and fix duplicate SKU inconsistencies between WooCommerce and your ERP without losing orders
- How to reduce build time and avoid duplicate artifacts in CI for large PHP monoliths