我跟随Django Book到第7章。当我尝试联系的例子时,我遇到了这封邮件发送错误。
有谁知道如何解决这个问题?
以下是错误信息:
/ contact /错误
[Errno 10061]
请求方法:POST
Request URL: http://127.0.0.1:8000/contact/<br>
Django版本:1.5
例外类型:错误
例外值:[Errno 10061]
异常位置:在create_connection中的C:\ Python27 \ lib \ socket.py,第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 \高原双赢',
'C:\ Python27 \ lib中\ lib中-TK',
'C:\ Python27',
'C:\ Python27 \ LIB \站点包',
'C:\ Python27 \ LIB \站点包\ win32的',
'C:\ Python27 \ LIB \站点包\ 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', 'noreply@example.com'),
['siteowner@example.com'],
)
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))
答案 0 :(得分:0)
检查您的电子邮件设置是否正确:
settings.py:
DEFAULT_FROM_EMAIL =“youremail@gmail.com”
EMAIL_HOST =“smtp.gmail.com”
EMAIL_HOST_USER =“youremail@gmail.com”
EMAIL_HOST_PASSWORD =“yourpasswordforyouremailaccount”
EMAIL_PORT = 587
EMAIL_USE_TLS = True
据我所知,这些是gmail的设置。
答案 1 :(得分:-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 docs,https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-EMAIL_HOST