Django邮件发送错误:[错误10061]
我跟着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))
在你发送邮件,您必须在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
检查您的电子邮件设置是否正确:
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作为设置据我所知
您的邮件服务器是否正在运行并等待r连接指定的IP和端口? – Rohan 2013-03-14 04:42:24
你在你的设置中有电子邮件配置吗? – catherine 2013-03-14 04:43:42