Unable to send mail with Sylius Swiftmailer from localhost docker-mailserver

Viewed 34

I am trying to setup a local mailserver and send mail in Sylius using swiftmailer. Here is my swiftmailer.yaml config:

   swiftmailer:
    transport: 'smtp'
    auth_mode: login
    username: 'test@dibdrop.dev'
    password: 'test'
    disable_delivery: false

And my docker-composer.yml for docker-mailserver:

services:
  mailserver:
    image: docker.io/mailserver/docker-mailserver:latest
    container_name: mailserver
    # If the FQDN for your mail-server is only two labels (eg: example.com),
    # you can assign this entirely to `hostname` and remove `domainname`.
    hostname: mail
    domainname: dibdrop.dev
    env_file: mailserver.env
    # More information about the mail-server ports:
    # https://docker-mailserver.github.io/docker-mailserver/edge/config/security/understanding-the-ports/
    # To avoid conflicts with yaml base-60 float, DO NOT remove the quotation marks.
    ports:
      - "25:25"    # SMTP  (explicit TLS => STARTTLS)
      - "143:143"  # IMAP4 (explicit TLS => STARTTLS)
      - "465:465"  # ESMTP (implicit TLS)
      - "587:587"  # ESMTP (explicit TLS => STARTTLS)
      - "993:993"  # IMAP4 (implicit TLS)
    volumes:
      - ./docker-data/dms/mail-data/:/var/mail/
      - ./docker-data/dms/mail-state/:/var/mail-state/
      - ./docker-data/dms/mail-logs/:/var/log/mail/
      - ./docker-data/dms/config/:/tmp/docker-mailserver/
      - /etc/localtime:/etc/localtime:ro
    restart: always
    stop_grace_period: 1m
    cap_add:
      - NET_ADMIN
    healthcheck:
      test: "ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1"
      timeout: 3s
      retries: 0

I can connect without problem to the mailserver using 'telnet smtp.localhost 25, but when I try to send via sylius the output is :

Connection could not be established with host localhost :stream_socket_client(): Unable to connect to localhost:25 (Address not available)

I have also tried to set the host to 'smtp.localhost' instead of 'localhost' but it wasn't changing anything. I'll appreciate any comments to help me understand better how mailservers work and why it's not working in my situation

0 Answers
Related