2012-09-21 67 views
1

我用django-registration为我的项目管理用户注册,登录,等等。但是当我申请帐户了,我碰到这个问题来了:Django的注册SMTPServerDisconnected错误

SMTPServerDisconnected

为了记录在案,我在我的settings.py中配置了电子邮件相关的设置:

EMAIL_HOST = 'smtp.gmail.com'                                   
EMAIL_PORT = 465 
EMAIL_USE_TLS = True 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = 'mypassword' 

另外我也有所有需要和可访问的模板。所以这个问题与此无关。

更多错误描述:

我点击发送激活邮件后,需要很长的时间才终于给这个错误。

这里是回溯(未完成):

SMTPServerDisconnected at /accounts/register/ 

Connection unexpectedly closed 

last trace back: 

/usr/lib/python2.7/smtplib.py in getreply 

        line = self.file.readline() 

       except socket.error as e: 

        self.close() 

        raise SMTPServerDisconnected("Connection unexpectedly closed: " 

               + str(e)) 

       if line == '': 

        self.close() 

        raise SMTPServerDisconnected("Connection unexpectedly closed") 

    ... 

       if self.debuglevel > 0: 

        print>>stderr, 'reply:', repr(line) 

       resp.append(line[4:].strip()) 

       code = line[:3] 

       # Check that the error code is syntactically correct. 

       # Don't attempt to read a continuation line if it is broken. 

感谢您的任何建议。

回答

2

最后我想通了这一点。我在这里发布我的解决方案,以防其他人卡在这里。问题是Gmail端口。使用587,它的工作。

我是在这里看到:https://code.djangoproject.com/ticket/9575

我不知道为什么有些人可以用465,有些却不能。我花了几个小时才知道。希望你们的人不会!

编辑:请参阅h ere了解关于使用端口的更多讨论。

To use port 465, you need to call smtplib.SMTP_SSL(). Currently, it looks like Django only uses smtplib.SMTP(). 

似乎587是正确的选择。

0

如果您没有上述的答案如果幸运的话,你可能要检查,看看是否你已经在settings.py设置你的DEFAULT_FROM_EMAIL

# project/settings.py 
    EMAIL_HOST = 'smtp.gmail.com'                                   
    EMAIL_PORT = 465 
    EMAIL_USE_TLS = True 
    EMAIL_HOST_USER = '[email protected]' 
    EMAIL_HOST_PASSWORD = 'mypassword' 
    DEFAULT_FROM_EMAIL = '[email protected]'