我的文件
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当我使用命令运行这个容器时
docker build -t test-smtp-image . && docker run -p 8025:8025 --name skad-test-smtp test-smtp-image 并将邮件从运行容器的主机绑定到它,我得到了下一个异常。
raise SMTPConnectError(
aiosmtplib.errors.SMTPConnectError: Error connecting to 127.0.0.1 on port 8025: Unexpected EOF received但是,当我用相同的脚本和aiosmtpd在主机上运行命令发送电子邮件时,效果很好。
发送邮件脚本:
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))发布于 2022-04-26 13:08:22
多亏了David Maze。
正确的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:8025https://stackoverflow.com/questions/71966626
复制相似问题