When a message vanishes, the mail log is the first and best witness. Every mail transfer agent records what it received, what it tried to deliver, what the remote server answered and what it finally did. Postfix is among the most common MTAs and its logs are compact, consistent and easy to search once you recognise the pattern. This guide uses Postfix lines as examples, but the same ideas apply to Exim, Sendmail and the logs of managed relays: find the message identifier, follow it through each step, read the remote reply and decide whether the problem is yours, the recipient's or in between. It complements managing the mail queue, tracing messages and SMTP reply codes.
Where the logs live
| System | Typical location or command |
|---|---|
| Debian and Ubuntu with rsyslog | /var/log/mail.log (and mail.err) |
| RHEL and derivatives | /var/log/maillog |
| systemd journal | journalctl -u postfix (the unit may be postfix@- on newer packages) |
| Containers | The container stdout, or the configured syslog target |
| Managed relay | The provider's message log or event API. See events |
Anatomy of a log line
Apr 14 10:02:11 mx1 postfix/smtpd[2214]: 4F1A2C0B7E: client=app1.example.com[203.0.113.10], sasl_method=PLAIN, [email protected]
Apr 14 10:02:11 mx1 postfix/cleanup[2219]: 4F1A2C0B7E: message-id=<[email protected]>
Apr 14 10:02:11 mx1 postfix/qmgr[1190]: 4F1A2C0B7E: from=<[email protected]>, size=5120, nrcpt=1 (queue active)
Apr 14 10:02:12 mx1 postfix/smtp[2230]: 4F1A2C0B7E: to=<[email protected]>, relay=mx.gmail.example[198.51.100.7]:25, delay=1.1, delays=0.05/0.01/0.5/0.5, dsn=2.0.0, status=sent (250 2.0.0 OK 1713088932 x12si1234)Reading from left to right: timestamp, host, the Postfix component and its process ID, the queue ID, then key=value fields. The components tell you the stage: smtpd received a connection, cleanup processed the message and added headers, qmgr scheduled it, smtp delivered it to the next hop, bounce generated a failure notice. Fields you will use most:
| Field | Meaning |
|---|---|
| client= | The connecting host and IP that submitted the message |
| sasl_username= | The authenticated user, if any |
| message-id= | The Message-ID header; useful to match what the sender sees |
| from=<> | The envelope sender. An empty address marks a bounce. See the null sender |
| to= | The envelope recipient for this delivery attempt |
| relay= | The next-hop server and port, or "none" if no connection was made |
| delay= and delays= | Total time and its parts: before queue manager / in queue manager / connection setup / transmission |
| dsn= | Enhanced status code (2.x.x success, 4.x.x temporary, 5.x.x permanent) |
| status= | sent, deferred, bounced, expired, or other outcome |
| text in parentheses | The remote server's reply, which usually contains the real explanation |
The status values
| Status | What it means | What to do |
|---|---|---|
| sent | The next hop accepted the message (a 250 reply) | Delivery to the next server succeeded; for relays "sent" only means handed on |
| deferred | Temporary failure; Postfix will retry | Read the reply: greylisting, rate limiting, DNS or connection problems |
| bounced | Permanent failure; a non-delivery report goes to the sender | Fix the cause (bad address, policy, authentication) and resend |
| expired | Retries exceeded the maximal queue lifetime | Investigate why it stayed deferred. See the queue |
| rejected (NOQUEUE reject) | Refused at SMTP time by your own server, before queueing | Check restrictions, authentication or the client IP |
| milter-reject / policy | A filter refused the message | Look at the filter that produced the text |
Tracing one message
- Find the queue ID. Search by recipient:
grep "to=<[email protected]>" /var/log/mail.log, or by Message-ID. - Collect all lines for that ID.
grep 4F1A2C0B7E /var/log/mail.logreturns receipt, queueing and every delivery attempt in order. - Check the receipt step. Who submitted it, was authentication used, and did the client IP match what you expect?
- Check each delivery attempt. Note the relay host, the dsn value and the remote text.
- Follow bounces. A bounce message has its own queue ID; the line with
from=<>links back to the original through the text of the report. - Compare timestamps. Long gaps between attempts point to queue backoff; long delays in the second figure of delays point to a slow queue manager; large last figures point to a slow remote server.
- Decide the owner. Reply codes 4xx and 5xx from the remote host usually mean the remote side or your reputation; local errors (no route, DNS failure, connection timed out) mean your network or configuration.
Common patterns and their meanings
| Log text (shortened) | Likely cause | Next step |
|---|---|---|
| status=deferred (host mx... said: 421 4.7.0 Try again later, rate limited) | Provider throttling your IP or domain | Slow the rate; check reputation. See 421 errors |
| status=deferred (connect to ...: Connection timed out) | Firewall, port 25 blocked, remote outage | Test with telnet or openssl from the server |
| status=bounced (host ... said: 550 5.1.1 User unknown) | Recipient does not exist | Remove the address |
| status=bounced (550 5.7.1 ... blocked / listed) | IP or domain on a blocklist or policy refusal | Use the blocklist check and follow the removal steps |
| status=bounced (550 5.7.26 ... authentication) | SPF/DKIM/DMARC failure | Check records. See Authentication-Results |
| status=deferred (Host or domain name not found) | DNS failure for the recipient domain | Check resolver settings and recipient domain |
| NOQUEUE: reject: RCPT ... Relay access denied | Client not allowed to relay | Fix authentication or restrictions. See open relay checks |
| SASL LOGIN authentication failed | Wrong credentials or brute force | Check for repeated attempts. See brute-force defence |
| TLS library problem or certificate verify failed | Certificate or protocol mismatch | Review TLS settings. See certificates |
| warning: ... queue file write error / disk full | Local storage problem | Free space and requeue |
Useful commands
# Count statuses today
grep "status=" /var/log/mail.log | grep -o "status=[a-z]*" | sort | uniq -c
# Top remote error reasons for deferrals
grep "status=deferred" /var/log/mail.log | sed -E "s/.*\(([^)]*)\).*/\1/" | sort | uniq -c | sort -rn | head
# Messages queued now
postqueue -p | tail -n 1
# Details for one queued message
postcat -q 4F1A2C0B7E | head -40For heavy volume use log analysers or ship logs to a central store so you can search by recipient domain and status over time. Keep logs long enough to cover the retention you promise customers and for investigating delayed complaints. Mask personal data where policy requires and restrict who can read the logs.
Reading delays
The delays field is a compact timeline with four numbers in seconds. The first is time before the queue manager, including receipt and cleanup. The second is time waiting in the queue manager. The third is connection setup, including DNS, the TCP handshake and TLS. The fourth is the actual transmission of the message and the remote reply. A large first value suggests a busy or slow content filter on your side, a large second value suggests a backlog or retry waiting, a large third value points to DNS or network trouble and a large fourth value means the remote server was slow to accept the data or to respond after it. If many messages show the same slow stage, look at that stage rather than at individual messages. Compare delays for different recipient domains: when only one domain is slow, the cause is probably at that domain, and when every domain is slow, it is most likely your own server, resolver or network.
Logging for relays and APIs
If you send through a relay or API, you do not have the relay logs on your server, but you still keep your own application log. Record the message identifier returned at submission time, the recipient and the time, so you can match it later with the relay events for that identifier. A short line in the application log, with the identifier and the result of the submission, often saves hours of searching. Where the relay offers webhooks, store the delivery, bounce and complaint events together with that identifier, so one search shows the whole lifecycle in a single place.
What to send when asking for help
- All log lines for the queue ID, from receipt to final status.
- The full SMTP reply text, including the enhanced status code.
- The sending IP, the recipient domain and the time with timezone.
- The original message headers if you have them.
- What changed recently: a new IP, DNS update, software upgrade or sending campaign.
With the queue ID in hand a mail log tells a clear story: who submitted the message, what you tried and exactly what the other server said. Learn to read that story quickly and most delivery problems become routine.
Test your sending path Check records and blocklists before digging into logs.
References and further reading
Frequently asked questions
What is a Postfix queue ID?
A unique identifier assigned to a message in the queue; every log line for that message carries it so you can follow it.
What is the difference between deferred and bounced?
Deferred is a temporary failure that Postfix retries; bounced is a permanent failure that generates a non-delivery report.
Where do I find the reason for a failure?
In the text in parentheses after status, which holds the remote server reply, and in the dsn enhanced status code.
Does status=sent mean the recipient received it?
No. It means the next server accepted it. Later filtering may still place it in spam or discard it.
How do I trace one message?
Find its queue ID by searching the recipient or Message-ID, then grep every line with that ID.