SMTP server not working - Swift_TransportException: Connection could not be established

Hi All,

I am searching in the forum the whole day and don’t get any further with my issue :frowning:

I am running NC 24.0.3 in a pretty much standard Docker configuration:

version: '3.1'

services:
  redis:
    image: redis:alpine
    restart: always
    volumes:
      - ./redis:/data
    networks:
      - proxy-tier
  
  proxy:
    image: jwilder/nginx-proxy
    ports:
      - 192.168.178.3:80:80
      - 192.168.178.3:443:443
    volumes:
      - ./proxy/conf.d:/etc/nginx/conf.d
      - ./proxy/vhost.d:/etc/nginx/vhost.d
      - ./proxy/html:/usr/share/nginx/html
      - ./proxy/certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - proxy-tier

    restart: always

  letsencrypt-companion:
    image: nginxproxy/acme-companion
    volumes_from:
      - proxy
    volumes:
      #- ./proxy/conf.d:/etc/nginx/conf.d
      #- ./proxy/vhost.d:/etc/nginx/vhost.d
      #- ./proxy/html:/usr/share/nginx/html
      - ./proxy/acme:/etc/acme.sh
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./proxy/certs:/etc/nginx/certs:rw
    environment:
       - DEFAULT_EMAIL=admin@graf-online.me
    restart: always

  web:
    image: nginx
    links:
      - app
    volumes:
      - ./web/nginx.conf:/etc/nginx/nginx.conf
      - ./www:/var/www/html
      - ./nextcloud/apps:/var/www/html/apps
      - ./nextcloud/custom_apps:/var/www/html/custom_apps
      - ./nextcloud/config:/var/www/html/config
      - /share/Nextcloud-DATA/NC_DATA:/var/www/html/data
    environment:
      - VIRTUAL_HOST=
      - VIRTUAL_NETWORK=nginx-proxy-prod
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=
      - LETSENCRYPT_EMAIL=
      - LC_ALL=C.UTF-8
      - LANG=C
#    ports:
#      - 192.168.178.3:81:80
    links:
      - "clamav:av"
    networks:
      - proxy-tier
    restart: always

  app:
    #image: nextcloud:fpm
    build: ./nextcloud
    volumes:
      - ./www:/var/www/html
      - ./nextcloud/apps:/var/www/html/apps
      - ./nextcloud/custom_apps:/var/www/html/custom_apps
      - ./nextcloud/config:/var/www/html/config
      - ./nextcloud/php_config:/usr/local/etc/php/conf.d
      - /share/Nextcloud-DATA/NC_DATA:/var/www/html/data
    networks:
      - proxy-tier
    restart: always
    environment:
      - NEXTCLOUD_ADMIN_USER_FILE=/run/secrets/NEXTCLOUD_ADMIN_USER
      - NEXTCLOUD_ADMIN_PASSWORD_FILE=/run/secrets/NEXTCLOUD_ADMIN_PASSWORD
      - MYSQL_PASSWORD_FILE=/run/secrets/MYSQL_PASSWORD
      - MYSQL_DATABASE_FILE=/run/secrets/MYSQL_DATABASE
      - MYSQL_USER_FILE=/run/secrets/MYSQL_USER
      - MYSQL_HOST=
      - SMTP_HOST=
      - SMTP_SECURE=tls
      - SMTP_PORT=587
      - SMTP_AUTHTYPE=LOGIN
      - SMTP_NAME=@
      - SMTP_PASSWORD_FILE=/run/secrets/SMTP_PASSWORD
      - MAIL_FROM_ADDRESS=
      - MAIL_DOMAIN=
      - LC_ALL=C.UTF-8
      - LANG=C
      - REDIS_HOST=redis

    links:
      - "clamav:av"
    depends_on:
      - redis
    secrets:
      - NEXTCLOUD_ADMIN_USER
      - NEXTCLOUD_ADMIN_PASSWORD
      - MYSQL_PASSWORD
      - MYSQL_DATABASE
      - MYSQL_USER
      - SMTP_PASSWORD

  cron:
    image: nextcloud:fpm
    restart: always
    volumes:
      - ./www:/var/www/html
      - ./nextcloud/apps:/var/www/html/apps
      - ./nextcloud/custom_apps:/var/www/html/custom_apps
      - ./nextcloud/config:/var/www/html/config
      - /share/Nextcloud-DATA/NC_DATA:/var/www/html/data
    entrypoint: /cron.sh
    environment:
    - REDIS_HOST=redis
    - SMTP_HOST=
    - SMTP_SECURE=tls
    - SMTP_PORT=587
    - SMTP_AUTHTYPE=LOGIN
    - SMTP_NAME=
    - SMTP_PASSWORD_FILE=/run/secrets/SMTP_PASSWORD
    depends_on:
      - redis
    networks:
      - proxy-tier
    secrets:
      - SMTP_PASSWORD

  clamav:
    image: mkodockx/docker-clamav:alpine
    restart: always
    volumes:
      - ./clamav:/var/lib/clamav
    networks:
      - proxy-tier
      
networks:
  proxy-tier:
    external:
      name: nginx-proxy-prod
secrets:
  NEXTCLOUD_ADMIN_USER:
  NEXTCLOUD_ADMIN_PASSWORD:
  MYSQL_PASSWORD:
  MYSQL_DATABASE:
  MYSQL_USER:
  SMTP_PASSWORD:

OK, probably not that standard - but my problems are not related to the docker compose file.

My problem is that I am not able to configure my smtp server correctly.
After turning smtp logging on I saw the following errormessage in the logs:

Swift_TransportException: Connection could not be established with host 127.0.0.1 :stream_socket_client(): Unable to connect to 127.0.0.1:25 (Connection refused) Log data: ++ Starting Swift_SmtpTransport !! Connection could not be established with host 127.0.0.1 :stream_socket_client(): Unable to connect to 127.0.0.1:25 (Connection refused) (code: 0)

Then I was checking my mail configuration using OCC:

     "mail_sendmailmode": "smtp",
        "default_phone_region": "DE",
        "mail_smtpdebug": true,
        "mail_smtpmode": "smtp",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "587",
        "mail_smtpsecure": "tls",
        "mail_smtpauth": true,
        "mail_smtpauthtype": "LOGIN",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***"

Which hopefully reflects the settings I have done via the environment variables for the container.

However, Swift is trying to connect to localhost:25 even though there is a different server in the config.

Does anyone has an idea where I can look further into that issue to find the root cause?

As a side note - I also tried to configure the smtp server via the GUI and this doesn’t work either.
I also found the older threat about gmail an MFA - but I am running my own SMTP server and this server is definitely running and only requires Username:Password to log in.

Thanks for your help!