I have 2 containers running through docker-compose, one with Django, the other with Mailhog. But when I send_mail through Django python manage.py runserver, it is possible to send, if i run a docker-compose up when I send email this error is returned:
[Errno 111] Connection refused
My docker-compose is:
services:
    mailhog:
        image: mailhog/mailhog
        logging:
            driver: 'none' # disable saving logs
        ports:
            - 1025:1025 # smtp server
            - 8025:8025 # web ui
        networks:
            - my_net
    api:
        build: .
        container_name: my_api
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
            - .:/src
        ports:
            - '8000:8000'
        env_file:
            - '.env'
        depends_on:
            - mailhog
        networks:
            - my_net
networks:
    my_net:
My env file is:
EMAIL_HOST = '0.0.0.0'
EMAIL_PORT = '1025'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
What should I do?
                        
Found it, i had to change 2 things:
1- changed my docker-compose, adding a container_name to mailhog container and linking api to mailhog
2- and changed my EMAIL_HOST to the docker container_name