开发者社区> 问答> 正文

django 发邮件 报错 连接数太多????报错

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 模板:



<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>

报错信息:

SMTPConnectError at /contact/

(421, '#4.4.5 Too many connections to this host.')
是我邮箱配置的不对? 还是我没设置什么?

觉得代码没问题啊。


展开
收起
爱吃鱼的程序员 2020-06-22 17:32:21 516 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    把页面完整的错误贴出来看看,<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'

    2020-06-22 17:32:38
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载