1

我刚刚在 Ubuntu 12.04 上安装了 Django 并尝试发送一条消息,我收到以下错误:

#from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['email@gmail.com'])
send.email()

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 255, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 88, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 49, in open
    local_hostname=DNS_NAME.get_fqdn())
  File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 309, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket
    return socket.create_connection((port, host), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 110] Connection timed out

有趣的是,我对 Haystack 也有同样的问题

[error] 19704#0: *10 upstream prematurely closed connection while reading response header from upstream, client: 201.2*3.**.85, server: www.myserver.com, request: "POST /account/register/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "www.myserver.com", referrer: "http://www.myserver.com/account/register/"


#uWSGI Configuration

[uwsgi]
uid = www-data
gid = www-data
chdir = /var/www/myserver.com/virtual/project
virtualenv = /var/www/myserver.com/virtual
plugins = python
master = True
vacuum = True
processes = 2
harakiri = 12
post-buffering = 4096
max-requests = 4000
module = project.wsgi:application

谢谢。

4

1 回答 1

0

在 django 中发送电子邮件,您必须在settings.py. 还要确保电子邮件主机和登录详细信息正确无误。

EMAIL_HOST          = 'smtp.gmail.com'
EMAIL_PORT          = 587
EMAIL_HOST_USER     = 'name@gmail.com'
EMAIL_HOST_PASSWORD = 'gmail_password'
EMAIL_USE_TLS       = True
EMAIL_BACKEND       = 'django.core.mail.backends.smtp.EmailBackend'
于 2013-08-17T06:23:30.280 回答