I use HAProxy as mail frontend (IMAPS) in SSL termination mode (mail clients configured to imap server (haproxy host)).


frontend ft_imaps
    mode tcp
    bind ssl crt /etc/pki/tls/certs/cert.pem
    default_backend bk_imaps2
    log global
    timeout client 1m
    option tcplog

backend bk_imaps
      mode tcp
      log global
      option tcplog
      timeout server 1m
      timeout connect 30s
      server SRV1 check maxconn 20 ssl verify none

All ok if all virtual domains served by server But if I want route mail traffic to virtual domain 'domain1.local' to and 'domain2.local' - to another (for example,, how can I filter this on HAProxy?

As for me, it is impossible, because HAProxy can't analize to which virtual domain every email. On configuration.txt: mode tcp is for SSL, SSH, SMTP. And in tcp mode "no layer 7 examination will be performed". So, SMTP headers is not accessed in tcp mode.

So, if I need use one point for mail traffic, I can try acl based on src (client ip address) or make several frontends (:1994 ->, :1995 -> and setup client mail software?

'mode http' is not suitable for this?

  • Does this answer your question? haproxy multihost with ssl acl – Gerald Schneider May 15 '20 at 9:35
  • The upvoted post (not the accepted one) shows how to handle multiple backends with SSL for different domains. However, it uses SNI, which is AFAIK not implemented in the SMTP protocol. I don't think this is possible with the SMTP protocol due to this, but I'm not an expert in this area and could be wrong. – Gerald Schneider May 15 '20 at 9:37
  • Interesting idea about SNI! – Marvin May 15 '20 at 10:03
  • If email client configured to HAProxy address (and only login point to email domain), SNI will not work, because domain (which will see SNI) is HAProxy address? – Marvin May 15 '20 at 10:20
  • In order to use SNI, HAProxy shoud receive mail traffic, but thi traffic should be addressed not for HAProxy host, but for certain services "behind" HAProxy? haproxy.com/blog/… – Marvin May 15 '20 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.