SMTPServerDisconnected:连接意外关闭:超时

时间:2017-11-16 11:06:06

标签: django sendgrid sentry

运行哨兵内部泊坞容器(版本8.20)并传入以下环境变量后:

-e SENTRY_EMAIL_HOST="smtp.sendgrid.net"
-e SENTRY_EMAIL_PORT=465
-e SENTRY_EMAIL_USE_TLS="True"
-e SENTRY_EMAIL_USER="apikey"
-e SENTRY_EMAIL_PASSWORD= '****'

我收到以下内容:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/tasks/base.py", line 54, in _wrapped
    result = func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sentry/tasks/email.py", line 76, in send_email
    send_messages([message])
  File "/usr/local/lib/python2.7/site-packages/sentry/utils/email.py", line 415, in send_messages
    sent = connection.send_messages(messages)
  File "/usr/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 87, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 48, in open
    local_hostname=DNS_NAME.get_fqdn())
  File "/usr/local/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python2.7/smtplib.py", line 317, in connect
    (code, msg) = self.getreply()
  File "/usr/local/lib/python2.7/smtplib.py", line 365, in getreply
    + str(e))
SMTPServerDisconnected: Connection unexpectedly closed: timed out

任何人都知道可能是什么原因?

2 个答案:

答案 0 :(得分:1)

根据Sendgrid Documentation

您也可以通过端口465上的SSL进行连接。

目前似乎django.core.mail.backends.smtp.EmailBackend不支持通过ssl发送电子邮件而只支持TSL。

我将端口更改为587,电子邮件按预期进行。

答案 1 :(得分:0)

现在,此功能可用。您可以设置自己的环境变量。

ctrl+shift+s

文件 |设置 |构建、执行、部署 |控制台 |适用于 Windows 和 Linux 的 Django 控制台

PyCharm |偏好 |构建、执行、部署 |控制台 |适用于 macOS 的 Django 控制台

将您的变量设置为变量部分。