Routing SMTP and IMAP with letsencrypt

I am trying to set-up a mail server with dovecot/postfix behind traefik reverse proxy.

What I'm trying to do is basically this (just focusing on dovecot):

|client| ----imap-ssl/tls----> |(993) traefik| ----imap-plaintext---->|(143) dovecot|

I know that I have to enable some sort of passthrough, to let the mail services "know" the client's IP (There is some sort of haproxy protocol that both postfix and dovecot implement).

On top of that I want to use traefik's letsencrypt certs for this tcp connection (to let traefik "enrich" the connection only between it and the client).

Pretty much all sollutions that i found using traefik and tcp is to have a dummy service for letsencrypt's http challenge, dump the certificates somehow, use the certificates directly in dovecot/postfix, and just use tls passthrough in traefik (seems a bit "hacky" to me).

So my question is: Is the setup for imap and smtp I mentioned above even possible with traefik's letsencrypt management? I know that this kind of setup is possible with haproxy, but I preffer traefik much more.


  • here what I'm trying to achieve in a "pseudo"-docker-compose.yml:
version: '3.3'


    image: "traefik:v2.8"
    container_name: "traefik"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.imaps.address=:993"
      - "--certificatesresolvers.mailresolver.acme.tlschallenge=true"
      - ""
      - ""
      - "993:993"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./letsencrypt:/letsencrypt"

    image: some-mail-image:latest
    container_name: mail
      - "./mail/:/var/mail"
      - SUBDOMAIN=mail
      - "traefik.enable=true"
      - "traefik.tcp.routers.imaps.entrypoints=imaps"
      - "traefik.tcp.routers.imaps.rule=HostSNI(``)"
      - ""
      - "traefik.tcp.routers.imaps.tls.certresolver=mailresolver" 
  • the error I get regarding letsencrypt:
level=error msg="Unable to obtain ACME certificate for domains \"\": unable to generate a certificate for the domains []: error: one or more domains had a problem:\n[] acme: error: 400 :: urn:ietf:params:acme:error:connection :: Connection refused\n" ACME CA="" routerName=imaps@docker rule="HostSNI(``)" providerName=mailresolver.acme

Any help would be appreciated! Thanks.