2012-09-21 96 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]'