1

My Dockerfile

FROM python:3.10-alpine

LABEL Description="test smtp server"
EXPOSE 8025
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN python -m pip install --upgrade pip && pip install -r requirements.txt
CMD python3 -m aiosmtpd --nosetuid --debug --debug --listen 127.0.0.1:8025

When i run this container with command

docker build -t test-smtp-image . && docker run -p 8025:8025 --name skad-test-smtp test-smtp-image 

And tying to send email to it from host where container running i got next Exception

    raise SMTPConnectError(
aiosmtplib.errors.SMTPConnectError: Error connecting to 127.0.0.1 on port 8025: Unexpected EOF received

But it works great when i send email with same script and aiosmtpd running command on host

Sending mail script:

from email.message import EmailMessage
import aiosmtplib
import asyncio

m = EmailMessage()
m['From'] = "test@test.com"
m["To"] = 'test@test.com'
m["Subject"] = "Test subject"
m.set_content("Test msg")

loop = asyncio.get_event_loop()
r = loop.run_until_complete(aiosmtplib.send(m, hostname="127.0.0.1", port=8025))
Alpensin
  • 191
  • 1
  • 10
  • 1
    You need to `--listen 0.0.0.0:8025`; if it's `127.0.0.1` it won't be reachable from outside its own container. [Deploying a minimal flask app in docker - server connection issues](https://stackoverflow.com/questions/30323224/deploying-a-minimal-flask-app-in-docker-server-connection-issues) describes the same problem in a slightly different Python context. – David Maze Apr 22 '22 at 09:49

1 Answers1

0

Thanks to David Maze.

Correct Dockerfile:

FROM python:3.10-alpine

LABEL Description="test smtp server"
EXPOSE 8025
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN python -m pip install --upgrade pip && pip install -r requirements.txt
CMD python3 -m aiosmtpd --nosetuid --debug --debug --listen 0.0.0.0:8025
Alpensin
  • 191
  • 1
  • 10