python 2.7
django 1.5
views.py 代码:
from django.http import HttpResponse from django.shortcuts import render_to_response from django.core.mail import send_mail 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 not request.POST.get('email') or '@' not in request.POST['email']: errors.append('Enter a valid e-mail address.') if not errors: send_mail( request.POST['subject'], request.POST['message'], 'xxxx@sina.com', [request.POST.get('email','xxxx@qq.com')], ) return HttpResponseRedirect('/contact/thanks/') return render_to_response('contact_form.html',{'error':errors}) def thanks(request): return render_to_response('thanks.html')setting.py 配置:
#email config
EMAIL_HOST='smtp.sina.com.cn'
EMAIL_PORT = '25'
EMAIL_HOST_USER = 'xxxx@sina.com'
EMAIL_HOST_PASSWORD = xxx'
EMAIL_USE_TLS =True
SERVER_EMAIL = EMAIL_HOST_USER
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
<html> <head> <title> Contact us </title> </head> <body> {% if error %} <ul> {% for error in errors %} <li>{{ error }}</li> {% endfor %} </ul> {% endif %} <form action = "/contact/" method = "post"> {% csrf_token %} <p>Subject:<input type = "text" name = "subject"/></p> <p> Your e-mail(optional):<input type = "text" name = "email"/></p> <p> Message:<textarea name = "message" rows = "10" cols = "50"></textarea></p> <input type = "submit" value = "Submit"> </form> </body> </html>
报错信息:
(421, '#4.4.5 Too many connections to this host.')是我邮箱配置的不对? 还是我没设置什么?
觉得代码没问题啊。
把页面完整的错误贴出来看看,<imgsrc="http://www.oschina.net/js/ke/plugins/emoticons/images/81.gif"alt=""/> 最近我也在玩django,你在写什么项目?blog?我觉得这个信息就足够了吧。刚接触django找不到错误原因。没写啥~只是跟着thedjangobook写列子学习呢~
帮你找到两个地方,可以参考参考:
<atarget="_blank"rel="nofollow">http://stackoverflow.com/questions/14592729/django-mysql-too-many-connections
<atarget="_blank"rel="nofollow">https://groups.google.com/forum/#!topic/django-users/ZKR_1LTCH4M
这两个帖子说的都是django跟mysql连接的问题~我怀疑是setting.py中EAMIL配置的问题。或者我选择的新浪邮箱服务器不让这种形式的自动发邮件~<spanstyle="color:#333333;font-family:helvetica,arial,Corbel,Verdana,sans-serif;font-size:14px;line-height:22px;background-color:#FFFFFF;">The“toomanyconnectionsfromyourhost”erroristhetextoftheerrormessagethatiscomingbackfromtheSMTPserver.ItindicatesthattheSMTPserverhasalimitonhowmanysimultaneousopenconnectionsitwillacceptfromasingleIPaddress.Theremusthavebeenotherthreadsorprocesses(orapplications)withopenconnectionstothesameSMTPserverthatcausedyoutoexceedthelimit.
<spanstyle="color:#333333;font-family:helvetica,arial,Corbel,Verdana,sans-serif;font-size:14px;line-height:22px;background-color:#FFFFFF;">
<spanstyle="color:#333333;font-family:helvetica,arial,Corbel,Verdana,sans-serif;font-size:14px;line-height:22px;background-color:#FFFFFF;">在老外的blog找到解释
回复<aclass='referer'target='_blank'>@渔樵耕读:试试谢谢!你这段信息很有用啊!难道是因为我昨晚开着新浪邮箱的同时用django发邮件就会报错?@晓骏
我关闭了新浪的邮箱。然后仍然报错~
我把<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">EMAIL_USE_TLS=True这段注释了
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">就可以发邮件了~
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">不知道为什么。。。
<preclass="lang-pyprettyprintprettyprinted"><spanstyle="font-size:14px;vertical-align:baseline;background-color:transparent;">EMAIL_BACKEND<spanstyle="font-size:14px;vertical-align:baseline;background-color:transparent;">=<spanstyle="font-size:14px;vertical-align:baseline;background-color:transparent;color:#800000;">'django.core.mail.backends.smtp.EmailBackend'版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。