【问题标题】:Send email with django + gunicorn + nginx get timeout使用 django + gunicorn + nginx 发送电子邮件获取超时
【发布时间】:2020-05-23 06:17:12
【问题描述】:

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

本地 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】:

    好的,经过大量测试,我发现 EC2 实例对默认 smtp 端口连接有限制。将端口从 25 更改为 587 即可完美运行。

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

    【讨论】:

      猜你喜欢
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 1970-01-01
      • 2015-11-25
      • 2017-06-11
      相关资源
      最近更新 更多