我有一个Django应用程序,当我在本地运行它时,一切正常。但是在运行于Docker容器中的生产中,它无法再发送邮件了,我收到了错误

Traceback (most recent call last):
File "/app/training/schema.py", line 167, in mutate
   fail_silently=False,
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/mail/__init__.py", line 60, in send_mail
   return mail.send()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/mail/message.py", line 294, in send
   return self.get_connection(fail_silently).send_messages([self])
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 103, in send_messages
   new_conn_created = self.open()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 63, in open
   self.connection = self.connection_class(self.host, self.port, **connection_params)
File "/app/.heroku/python/lib/python3.6/smtplib.py", line 251, in __init__
  (code, msg) = self.connect(host, port)
File "/app/.heroku/python/lib/python3.6/smtplib.py", line 336, in connect
  self.sock = self._get_socket(host, port, self.timeout)
File "/app/.heroku/python/lib/python3.6/smtplib.py", line 307, in _get_socket
  self.source_address)
File "/app/.heroku/python/lib/python3.6/socket.py", line 724, in create_connection
  raise err
File "/app/.heroku/python/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address

我正在使用以下设置:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587

有人知道我在做什么错吗?

最佳答案

我会从您的生产主机在端口587处检查到目标主机smtp.gmail.com的连接状态。

10-08 19:22