- Postfix connection cache
- Postfix caching connection timeout
- Postfix keeps reporting “Connection timed out”
If you happen to find connection timeout reports from Mail delivery reports or directly from log, having a similar information like follows:
Jan 11 07:32:14 server-smtp-01 postfix/error: 62E6DEBAD: to=<firstname.lastname@example.org>, relay=none, delay=17159, delays=17159/0.04/0/0.04, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to mailserver.xx.es[194.X.187.X]:25: Connection timed out)
..but at the same time, if you run a telnet operation it works without any problem:
telnet 194.X.187.X 25 Trying 194.X.187.X... Connected to 194.X.187.X. Escape character is '^]'. 220 mailserver.xx.es ESMTP
In such context, even if you restart postfix you still find out that it keeps reporting “Connection timed out”.
At the same time, you already checked that no firewall is blocking that connection: for example, root might be allowed to run telnet over such port but not “postfix” user.
Why Postfix keep on reporting “Connection timed out”
All these “Connection timed out” reported by Postfix are usually caused by the postfix connection cache state code: http://www.postfix.org/CONNECTION_CACHE_README.html
That caching code is used by Postfix to speed up operations and avoid keep on talking with slow or failing hosts. It is a performance improvement that, in some cases, might cause problems to you.
At some point in the past, the destination SMTP server started failing with a timeout. Then, that state was cached by postfix causing this problem.
How to solve “Connection timed out” when telnet works
First, try to review configuration parameter “smtp_connect_timeout” to increase it. By default 30 seconds is configured. Do not increase it more than 90 because it might cause you other problems.
After that, run the following commands to requeue and restart postfix. Remember, this will retry everything:
postsuper -r ALL /etc/init.d/postfix restart