Docker Compose E-Mail via SMTP not working

After testing for a while I tried to setup a production instance. For adding a second user account I need a working SMTP mailer. Therefore I added some lines to the n8n environment at docker-compose.yml:

version: "3"

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ${DATA_FOLDER}/letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - N8N_EMAIL_MODE
      - N8N_SMTP_HOST
      - N8N_SMTP_USER
      - N8N_SMTP_PASS
      - N8N_SMTP_SENDER
#      - N8N_SMTP_PORT
#      - N8N_SMTP_SSL


    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n
      - /local-files:/files

Additionally I added those values to the .env file including the credentials:

N8N_EMAIL_MODE=smtp
N8N_SMTP_HOST=xxxxxx.netcup.net
#N8N_SMTP_PORT=465
N8N_SMTP_USER="xxx@yyy.de"
N8N_SMTP_PASS="xxxxxxxxxx"
N8N_SMTP_SENDER=N8N
#N8N_SMTP_SSL=true

I tried it with putting the credentials directly into the docker-compose file, I tried it with putting them into the .env file, I tried it with commenting and uncommenting SSL and Port values, but in all cases I’m getting:

Could not reinvite user
Failed to send email to xxxxx@yyyyy.de

The SMTP credentials are definetely correct and working on other clients such as Thunderbird or Roundcube.

Do you have a glitch what I’m doing wrong or some ideas to log more specificly?

Thanks a lot!

Hi @mokkin, welcome to the community! I am sorry to hear you’re having trouble.

I have used a bunch of different email providers with n8n now and didn’t have any trouble so far, though Netcup was unfortunately not amongst them. I wonder if this could be a problem with the SSL versions used by Netcup vs. the ones support by our SMTP library.

In a first step, could you try setting N8N_SMTP_SENDER to a valid sender email for your email account?

If this doesn’t solve the problem, perhaps you can try setting N8N_SMTP_SSL=false and N8N_SMTP_PORT=587? From looking at this forum post it seems that would be the port for TLS connections on Netcup, so seems worth a shot.

That was the solution! I just put “N8N” there, assuming it would add the sender mail address automatically.
Since adding the address it worked immediately!

Thank you for your quick help!

Sweet, glad to hear it was just that :slight_smile:. Thanks for confirming!