2013-03-14 123 views
0

我跟着Django書到第7章。當我嘗試聯繫的例子時,我遇到了這個郵件發送錯誤。Django郵件發送錯誤:[錯誤10061]

有誰知道如何解決這個問題?

以下是錯誤信息:在/接觸

錯誤/
[錯誤10061]
請求方法:POST

Request URL: http://127.0.0.1:8000/contact/<br> 

Django的版本:1.5
異常類型:錯誤
異常值:[Errno 10061]
異常位置:C:\ Python27 \ lib \ socket.py in crea te_connection,線571
的Python可執行文件:C:\ Python27 \ python.exe
Python的版本:2.7.2
Python的路徑:
[ 'd:\工作區\ DJhello',
「d:\工作區\ DJhello '
'd:\工作區\ DJhello \ SRC',
'C:\ Python27 \的DLL',
'C:\ Python27 \ lib中',
' C:\ Python27 \ lib中\ plat- win',
'C:\ Python27 \ lib \ lib-tk',
'C:\ Python27',
'C:\ Python27 \ lib \ site-packages',
'C:\ Python27 \ lib \ site-packages \ win32',
'C:\ Python27 \ lib \ site-packages \ win32 \ lib',
'C:\ Python27 \ LIB \站點包\ PythonWin的',
'C:\ Python27 \ LIB \站點包\ setuptools的-0.6c11-py2.7.egg-信息',
「C: \ Windows \ System32下\ python27.zip']
服務器時間:星期四,2013年3月14日12點08分14秒+0800 enter code here

這裏是我的代碼:

def contact(request): 
    errors = [] 
    if request.method == 'POST': 
     if not request.POST.get('subject', ''): 
      errors.append('Enter a subject.') 
     if not request.POST.get('message', ''): 
      errors.append('Enter a message.') 
     if request.POST.get('email') and '@' not in request.POST['email']: 
      errors.append('Enter a valid e-mail address.') 
     if not errors: 
      send_mail(
       request.POST['subject'], 
       request.POST['message'], 
       request.POST.get('email', '[email protected]'), 
       ['[email protected]'], 
      ) 
      return HttpResponseRedirect('/contact/thanks/') 
    return render_to_response('contact_form.html', 
     {'errors': errors, 
     'subject': request.POST.get('subject', ''), 
     'message': request.POST.get('message', ''), 
     'email': request.POST.get('email', '')}, 
     context_instance=RequestContext(request)) 
+1

您的郵件服務器是否正在運行並等待r連接指定的IP和端口? – Rohan 2013-03-14 04:42:24

+1

你在你的設置中有電子郵件配置嗎? – catherine 2013-03-14 04:43:42

回答

-1

在你發送郵件,您必須在settings.py設置一些變量:

EMAIL_HOST = 'smtp.163.com' # replace with your smtp server's address 
EMAIL_POST = 25 # replace with your smtp server's port 
EMAIL_HOST_USER = 'username' # replace with your smtp server account username 
EMAIL_HOST_PASSWORD = 'abc' # replace with your smtp server account password 

注意:你應該有一個SMTP服務器或SMTP服務器戶頭。

如何獲得免費的smtp服務器帳戶?This site offers free smtp services.

也許你想鑽研Django文檔,https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-EMAIL_HOST

0

檢查您的電子郵件設置是否正確:

settings.py:

DEFAULT_FROM_EMAIL = 「[email protected]

EMAIL_HOST =「smtp.gmail。COM」

EMAIL_HOST_USER = 「[email protected]

EMAIL_HOST_PASSWORD = 「yourpasswordforyouremailaccount」

EMAIL_PORT = 587個

EMAIL_USE_TLS =真

這些是Gmail作爲設置據我所知