SMTP route not working for Mailcatcher Docker container

Hello,

Have been working with Traefik for the past few weeks and I seem to get the hang of it as most of the things are working now after some vigorous testing and learning.

Now I seem to have hit a roadblock I am not able to solve even though I think it is correct, it must be wrong because it does not work :sweat_smile:

I am running a server with Docker and have several Docker containers running successfully but these are all PHP applications. Now I am trying to setup a Docker container with Mailcatcher and it only works half. The webinterface on port 1080 I can see and it is shown but the SMTP part is not responding as it should. Here is the output:

telnet mailcatcher.domain.com 1025                                                                                                                                                                                                                                                                        
Trying 173.212.200.143...
Connected to mailcatcher.domain.com.
Escape character is '^]'.

When I press Enter here I see this response:

HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close

400 Bad RequestConnection closed by foreign host.

This makes me believe it is processing it as an http request instead of an smtp request.

There is an error in the Traefik dashboard. The error shown is:

RULE
Host(`mailcatcher.domain.com`)

NAME
mailcatcher-smtp@docker

ENTRYPOINTS
mailcatchersmtp

ERRORS
invalid rule: "Host(`mailcatcher.domain.com`)" , unsupported function: Host 

Could someone please have a look and tell me what I am doing wrong?

Thank you very much. :smiling_face:

Here is my setup

Trafeik.toml

[log]
  level = "DEBUG"
  filePath = '/var/log/traefik.log'

[accessLog]
  filePath = '/var/log/access.log'
  bufferingSize = 100

[providers]
  [providers.docker]
    watch = true
    exposedByDefault = false
    network = "traefik-proxy"

[entryPoints]
  [entryPoints.web]
    address = ":80"
    [entryPoints.web.http]
      [entryPoints.web.http.redirections]
        [entryPoints.web.http.redirections.entryPoint]
          to = "websecure"
          scheme = "https"
  [entryPoints.websecure]
    address = ":443"
    [entryPoints.websecure.http.tls]
      certResolver = "lets-encrypt"
  [entryPoints.mailcatcherweb]
    address = ":1080"
    [entryPoints.mailcatcherweb.http.tls]
      certResolver = "lets-encrypt"
  [entryPoints.mailcatchersmtp]
    address = ":1025"

[certificateResolvers]
  [certificatesResolvers.lets-encrypt]
    [certificatesResolvers.lets-encrypt.acme]
      storage = "/etc/traefik/acme.json"
      email = "some@mailaddress"
      tlsChallenge = true

[api]
  insecure = false
  dashboard = true

Mailcatcher docker-compose.yml

version: "3.8"
services:
  mailcatcher:
    image: dockage/mailcatcher:latest
    container_name: "mailcatcher"
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik-proxy"

      - "traefik.http.routers.mailcatcher-web.rule=Host('mailcatcher.domain.com')"
      - "traefik.http.routers.mailcatcher-web.entrypoints=mailcatcherweb"
      - "traefik.http.routers.mailcatcher-web.service=mailcatcher-web"
      - "traefik.http.services.mailcatcher-web.loadbalancer.server.port=1080"

      - "traefik.tcp.routers.mailcatcher-smtp.rule=HostSNI('mailcatcher.domain.com')"
      - "traefik.tcp.routers.mailcatcher-smtp.entrypoints=mailcatchersmtp"
      - "traefik.tcp.routers.mailcatcher-smtp.service=mailcatcher-smtp"
      - "traefik.tcp.services.mailcatcher-smtp.loadbalancer.server.port=1025"
    networks:
      - traefik-proxy

networks:
  traefik-proxy:
    external: true

UFW config

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
1080/tcp                   ALLOW       Anywhere                  
1025/tcp                   ALLOW       Anywhere                  
8025/tcp                   ALLOW       Anywhere                  
25/tcp                     ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443 (v6)                   ALLOW       Anywhere (v6)             
1080/tcp (v6)              ALLOW       Anywhere (v6)             
1025/tcp (v6)              ALLOW       Anywhere (v6)             
8025/tcp (v6)              ALLOW       Anywhere (v6)             
25/tcp (v6)                ALLOW       Anywhere (v6) 

I think Host does not work on plain TCP connections, only on HTTP.

I also believe you should not set a router service in labels when using Docker configuration discovery, try removing

traefik.tcp.routers.mailcatcher-smtp.service=mailcatcher-smtp

If you still get a HTTP response, then maybe Traefik is setting HTTP as default and you explicitly need to set it to TCP somewhere. Check the docs.

Hello,

Thank you for your input. I am still trying to get this up and running to no avail. I have changed the configuration somewhat and the service name is needed.

In the Traefik logs I see this:

time="2022-10-15T18:50:50Z" level=debug msg="Creating server 0 http://172.18.0.6:1080" entryPointName=mailcatcherweb serviceName=mailcatcher-web serverName=0 routerName=mailcatcher-web@docker
time="2022-10-15T18:50:50Z" level=debug msg="child http://172.18.0.6:1080 now UP"
time="2022-10-15T18:50:50Z" level=debug msg="Propagating new UP status"
time="2022-10-15T18:50:50Z" level=debug msg="Added outgoing tracing middleware mailcatcher-web" middlewareType=TracingForwarder entryPointName=mailcatcherweb routerName=mailcatcher-web@docker middlewareName=tracing
time="2022-10-15T18:50:50Z" level=debug msg="Creating middleware" entryPointName=mailcatcherweb middlewareType=Recovery middlewareName=traefik-internal-recovery
time="2022-10-15T18:50:50Z" level=debug msg="Adding route for traefik.domain.com with TLS options default" entryPointName=websecure
time="2022-10-15T18:50:50Z" level=debug msg="Creating TCP server 0 at 172.18.0.6:1025" routerName=mailcatcher-smtp@docker serviceName=mailcatcher-smtp entryPointName=mailcatchersmtp serverName=0
time="2022-10-15T18:50:50Z" level=debug msg="Adding TLS route for \"HostSNI(`mailcatcher.domain.com`)\"" entryPointName=mailcatchersmtp routerName=mailcatcher-smtp@docker
time="2022-10-15T18:50:50Z" level=debug msg="Adding route for mailcatcher.rolandd.com with TLS options default" entryPointName=mailcatcherweb

This looks all good to me, also in the Traefik dashboard all lights are green.

One thing I noticed is when I try to reach the SMTP server, I see nothing happening in the Traefik log. This seems to me that Traefik is not even picking up the request.

This is the container configuration:

CONTAINER ID   IMAGE                              COMMAND                  CREATED          STATUS                 PORTS                                                                                                                                        NAMES
4d2c4e58efc3   jeanberu/mailcatcher               "mailcatcher --foreg…"   3 minutes ago    Up 3 minutes           1025/tcp, 1080/tcp                                                                                                                           mailcatcher
421c301ad35d   traefik:v2.8                       "/entrypoint.sh trae…"   56 minutes ago   Up 56 minutes          0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:1025->1025/tcp, 0.0.0.0:1080->1080/tcp, 0.0.0.0:8025->8025/tcp                             traefik

Connecting to the SMTP server locally works, so I know the service is up and running.

Is there anyway to find out why Traefik does not seem to pick up the request in the first place?