使用django + gunicorn + nginx发送电子邮件超时

问题描述 投票:1回答:1

我正在尝试使用gunicorn + nginx在AWS中部署Django项目,但出现超时错误。我的电子邮件后端使用具有SMTP身份验证的AWS SES。前2封电子邮件正常发送,在这些之后,我收到此错误。该帐户已经是发送电子邮件的不受限制的限制。

本地django开发服务器工作正常,它正常发送电子邮件。在具有相同EC2规范的本地虚拟机中,通常会发送电子邮件。

在django shell中运行,我在发送第三封电子邮件时收到此日志:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "<console>", line 5, in sendE
  File "/home/ubuntu/myproj/share/forms.py", line 23, in share_email
    email_message.send()
  File "/home/ubuntu/.local/share/virtualenvs/myproj-rqmaW6Yv/lib/python3.7/site-packages/django/core/mail/message.py", line 291, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/ubuntu/.local/share/virtualenvs/myproj-rqmaW6Yv/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 103, in send_messages
    new_conn_created = self.open()
  File "/home/ubuntu/.local/share/virtualenvs/myproj-rqmaW6Yv/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 63, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.7/smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.7/smtplib.py", line 307, in _get_socket
    self.source_address)
  File "/usr/lib/python3.7/socket.py", line 727, in create_connection
    raise err
  File "/usr/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
```
Any idea?
django nginx gunicorn sendmail amazon-ses
1个回答
1
投票

很多测试之后,我发现EC2实例对默认的smtp端口连接有限制。将端口从25更改为587,即可正常使用。

更多信息:https://aws.amazon.com/es/premiumsupport/knowledge-center/smtp-connectivity-timeout-issues-ses/

© www.soinside.com 2019 - 2024. All rights reserved.