MailDev容器和Django容器之间的邮件传输
[Errno 111]拒绝连接
电子邮件流量到控制台后端工作,因此该功能应该是正确的。
send_mail(
'Subject here',
'Here is the message.',
'from@example.com',
['to@example.com'],
fail_silently=False
)
在我切换到SMTP后端并在Container中启动MailDev后,我得到了:
在settings.py 中[Errno 111]拒绝连接
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
壳牌中的:
sudo docker run -p 1080:80 -p 1025:25 --name maildev djfarrelly/maildev
我的Docker容器是:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a46040dd1259 djfarrelly/maildev "bin/maildev --web..." 11 seconds ago Up 9 seconds 0.0.0.0:1025->25/tcp, 0.0.0.0:1080->80/tcp maildev
4fed036f92d4 exposee "/usr/src/start.sh" 42 minutes ago Up 42 minutes 0.0.0.0:8000->8000/tcp exposee
2c2cf7ce19e9 winauth "gunicorn -b 0.0.0..." 43 minutes ago Up 43 minutes 127.0.0.1:9876->9876/tcp winauth
afe4a449aa01 postgres "docker-entrypoint..." 44 minutes ago Up 44 minutes 127.0.0.1:5432->5432/tcp postgres
settings.py中的我的设置为:
EMAIL_HOST = CONFIG.get('EMAIL_HOST', '127.0.0.1')
EMAIL_PORT = CONFIG.get('EMAIL_PORT', 1025)
EMAIL_USE_TLS = CONFIG.get('EMAIL_USE_TLS', False)
EMAIL_USE_SSL = CONFIG.get('EMAIL_USE_SSL', False)
我在config.json中的配置是:
"EMAIL_HOST": "127.0.0.1",
"EMAIL_PORT": 1025,
"EMAIL_USE_TLS": false,
"EMAIL_USE_SSL": false
答案 0 :(得分:0)
问题是您正尝试使用127.0.0.1
从一个容器连接到另一个容器。这不会起作用,这个地址将对应于发送请求的容器。
对于能够相互通信的容器,标准方法是将容器连接到公共网络。
sudo docker network create mail-net
sudo docker run --network main-net -p 1080:80 -p 1025:25 --name maildev djfarrelly/maildev
将发送请求的容器连接到网络:
docker network connect mail-net <container-name>
将主机从127.0.0.1
更改为maildev
EMAIL_HOST = CONFIG.get('EMAIL_HOST', 'maildev')
EMAIL_PORT = CONFIG.get('EMAIL_PORT', 25)