gpt4 book ai didi

django - 操作系统错误 : [Errno 99] Address not available - sending e-mail from django docker app with gmail smtp

转载 作者:行者123 更新时间:2023-12-02 18:27:34 26 4
gpt4 key购买 nike

我正在尝试从 docker 中的 django 应用程序发送电子邮件,但出现以下错误:

OSError at /accounts/mail/
[Errno 99] Address not available
Request Method: GET
Request URL: https://localhost:8000/accounts/mail/
Django Version: 2.2.5
Exception Type: OSError
Exception Value:
[Errno 99] Address not available

网络服务器日志:
web_1            | OSError: [Errno 99] Address not availableweb_1            | [17/Sep/2019 19:21:35] "GET /accounts/mail/ HTTP/1.1" 500 108369

My environment:Ubuntu 18.04DockerDjango + GunicornPostfix

I have no problem to send an e-mail outside docker, locally. I suppose that there might be a problem with smtp port inside docker, but I don't know how to fix that. I tried with postfix - same error.

View code from django:

from django.core.mail import EmailMessage  # didn't work also with send_mail

def email(request):
mail_subject = 'Activate your account'
message = 'test'
to_email = 'mail@mail'
email = EmailMessage(
mail_subject, message, to=[to_email]
)
email.send()
return redirect('index')

我的 docker-compose 文件的一部分。
version: '3.3'

services:
web:
build: ./app
command: python manage.py runsslserver 0.0.0.0:8000
...
ports:
- 8000:8000
- 587:587
- 25:25
env_file: .envdev
...
postfix:
image: juanluisbaptiste/postfix:latest
expose:
- "25"
env_file:
- .envpostfix
restart: always
volumes:
- "/etc/localtime:/etc/localtime:ro"
...

Docker .env 文件:
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_USE_TLS=True
EMAIL_HOST=smtp.gmail.com
EMAIL_HOST_USER=***
EMAIL_HOST_PASSWORD=***
EMAIL_PORT=587

我的后缀设置:
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=***
SMTP_PASSWORD=***
SERVER_HOSTNAME=127.0.0.1

最佳答案

问题解决了。

我在 django 设置中创建了 MAIL 变量,而不是只保留在 docker .env 文件中。

关于django - 操作系统错误 : [Errno 99] Address not available - sending e-mail from django docker app with gmail smtp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57981111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com