Dovecot Proxy LTMP client connect to TCP port 0

Wido den Hollander wido at
Sat Apr 9 09:25:42 UTC 2016


I am trying to set up a Dovecot proxy which proxies through POP3, IMAP and LTMP
towards a different Dovecot machine.

On the proxy machine I use a MySQL database as a userdb and passwdb backend and
it returns the proper information as described here:

IMAP and POP3 works just fine, but with LMTP I run into a problem.

On the 'proxy' machine Postfix is also running and it deliver locally to LTMP
via Socket:

virtual_transport = lmtp:unix:private/dovecot-lmtp

Dovecot there is also configured to proxy LTMP:

lmtp_proxy = yes

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0600
    user = postfix

So far so good. A telnet to localhost 110 or 143 allows me to log in to the

When Postfix delivers the message locally to Dovecot through LTMP it tries to
proxy it though.

When doing so it tries to connect to TCP port 0 (zero).

dovecot: lmtp(22580): Error: lmtp client: connect(, 0) failed:
Connection refused

I know I can return the 'port' field in the userdb query, but the same query is
used for POP3, IMAP and LMTP. So that can't be hardcoded.

I fixed it for now with a CASE statement in SQL:

password_query = SELECT b.hostname AS host, NULL AS password, \
       'Y' AS nopassword, AS destuser, 'Y' AS proxy, \
       CASE '%s' WHEN 'lmtp' THEN 2525 WHEN 'pop3' THEN 110 WHEN 'imap' THEN 143
END AS port \
FROM User u, Backend b, Domain d \
WHERE u.domainID = d.domainID \
AND b.backendID = d.backendID \
AND = '%u'

%s is a variable containing the service Dovecot is trying to look up.

This is however rather hacky.

On my destination machine LMTP is listening on port 2525. Is there any way to
tell the Dovecot LTMP client to connect to port 2525 by default?



More information about the dovecot mailing list