电子邮件发送在django代码不工作 [英] Email sending in django code is not working
本文介绍了电子邮件发送在django代码不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
电子邮件发送在django代码不工作,
它显示错误[Errno 10061]没有连接,因为目标机器主动拒绝它
这些是我的 VIEWS.PY
Email sending in django code is not working, it display error "[Errno 10061] No connection could be made because the target machine actively refused it" these are my VIEWS.PY
def send_email(request):
username = request.POST.get('username', '')
from_email = request.POST.get('from_email', '')
message = request.POST.get('message', '')
if username and message and from_email:
try:
send_mail(username, from_email, message, ['canonizadocharm@ymail.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return HttpResponseRedirect('/contact/thanks/')
else:
# In reality we'd use a form class
# to get proper validation errors.
return HttpResponse('Make sure all fields are entered and valid.')
我的 contact.html
<FORM METHOD="POST" ACTION="/send_email/" >
{% csrf_token %}
Name: <INPUT TYPE="text" NAME="username"><BR>
Email: <INPUT TYPE="text" NAME="from_email"><BR>
Message: <BR>
<TEXTAREA NAME="message" ROWS="10" WRAP="hard">
</TEXTAREA>
<INPUT NAME="redirect" TYPE="hidden">
<INPUT NAME="NEXT_URL" TYPE="hidden">
<BR>
<INPUT TYPE="submit" VALUE="Send">
<INPUT TYPE="reset" VALUE="Clear">
</FORM>
这些是我的 URLS.PY
url(r'^send_email/', views.send_email),
url(r'^contact/', views.contact),
url(r'^thanks/', views.thanks),
和我的 SETTINGS.PY
EMAIL_HOST = 'localhost'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 25
EMAIL_USE_TLS = True
推荐答案
您的操作
表单值必须直接查看的url, mailto:canonizadocharm@ymail.com
是
Your action
value of form must direct to view's url, mailto:canonizadocharm@ymail.com
is not a valid path on your server.
更新:
例如,添加一个新规则到urls.py喜欢,
For example, add a new rule to urls.py like,
url(r'^mail/', views.send_mail),
然后将操作值更改为邮件
。
这篇关于电子邮件发送在django代码不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文