邮件不是由 django-contact-form 应用程序发送的,并且没有错误消息
我已经安装了这个 django-contact-form 应用程序。 当我想通过联系表单向我的 Gmail 帐户发送电子邮件时,我没有收到任何错误,并且我被重定向到我的 contact_form_sent.html,但没有发送任何邮件。谁能帮我调试这个问题。这是 smtp 服务器的问题吗,因为我是从本地主机测试的???
我的配置如下,与Patrick Beeson的类似:
设置.py 我已经检查过其他电子邮件帐户及其适当的端口。
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
#('***', '***@googlemail.com'),
)
MANAGERS = ADMINS
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = '********'
EMAIL_HOST_USER = '******@googlemail.com'
EMAIL_PORT = 587 #465 or 587
#EMAIL_SUBJECT_PREFIX = 'Django Test mail'
EMAIL_USE_TLS = True
urls.py
(r'^contact/', include('contact_form.urls')),
contact_form.html
...
<form method="POST">
<ol>
{{ form.as_p }}
<li>
<input type="submit" name="submit" value={% trans "Senden" %} />
<div class="clr"></div>
</li>
</ol>
</form>
...
{{ name }}
{{ email }}
{{ body }}
contact_form.txt contact_form_sent.html
{% block content %}
<h2>{% trans "Your message was sent." %}</h2>
{% endblock %}
contact_form_subject.txt
message from {{ name }}
在我的 contact_form.html 中设置 action="."
并添加 print request.POST
时进行编辑
,我在本地主机的开发服务器中得到了这个,单击提交按钮后:
<QueryDict: {u'body': [u'This is my Test message for you !!\r\n\r\nBest Regards\r\nMr. NoOne'], u'name': [u'testname'], u'submit': [u'Send'], u'email': [u'anyone@myemail.
com']}>
已编辑
如果我编写自己的 view.py,我会收到此错误:
Request Method: POST
Request URL: http://127.0.0.1:8000/en/contact/
Exception Type: error
Exception Value:
(10065, 'No route to host')
Exception Location: C:\Python25\lib\smtplib.py in connect, line 310
Python Executable: C:\Python25\python.exe
Python Version: 2.5.0
Python Path: ['H:\\webpage', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages']
我新的自己的 view.py 看起来像:
from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.mail import send_mail
from contact_form.forms import ContactForm
def email_contact(request, form_class=ContactForm, template_name='contact_form/contact_form.html'):
form = form_class(data=request.POST, files=request.FILES, request=request)
if request.method == "POST":
send_mail('Subject here', 'Here is the message.', '[email protected]', ['[email protected]'], fail_silently=False)
print request.POST
return render_to_response(template_name, { 'form': form }, context_instance=RequestContext(request))
这里出了什么问题?
I've installed this django-contact-form app.
When I want to send an email to my gmail account via contact form I get no error and I am redirected to my contact_form_sent.html, but there is no mail sent. Can anyone help me in debugging this issue. Is this a problem of smtp server, because I am testing from localhost???
My configurations are as follows, it is similar to Patrick Beeson's :
settings.py
I have already checked other email accounts and their appropiate ports.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
#('***', '***@googlemail.com'),
)
MANAGERS = ADMINS
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_PASSWORD = '********'
EMAIL_HOST_USER = '******@googlemail.com'
EMAIL_PORT = 587 #465 or 587
#EMAIL_SUBJECT_PREFIX = 'Django Test mail'
EMAIL_USE_TLS = True
urls.py
(r'^contact/', include('contact_form.urls')),
contact_form.html
...
<form method="POST">
<ol>
{{ form.as_p }}
<li>
<input type="submit" name="submit" value={% trans "Senden" %} />
<div class="clr"></div>
</li>
</ol>
</form>
...
contact_form.txt
{{ name }}
{{ email }}
{{ body }}
contact_form_sent.html
{% block content %}
<h2>{% trans "Your message was sent." %}</h2>
{% endblock %}
contact_form_subject.txt
message from {{ name }}
EDITED
when setting action="."
in my contact_form.html and adding print request.POST
I get this in my development server at localhost, after clicking the submit button:
<QueryDict: {u'body': [u'This is my Test message for you !!\r\n\r\nBest Regards\r\nMr. NoOne'], u'name': [u'testname'], u'submit': [u'Send'], u'email': [u'anyone@myemail.
com']}>
EDITED
If I write my own view.py I get this error:
Request Method: POST
Request URL: http://127.0.0.1:8000/en/contact/
Exception Type: error
Exception Value:
(10065, 'No route to host')
Exception Location: C:\Python25\lib\smtplib.py in connect, line 310
Python Executable: C:\Python25\python.exe
Python Version: 2.5.0
Python Path: ['H:\\webpage', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages']
my new own views.py looks like:
from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.mail import send_mail
from contact_form.forms import ContactForm
def email_contact(request, form_class=ContactForm, template_name='contact_form/contact_form.html'):
form = form_class(data=request.POST, files=request.FILES, request=request)
if request.method == "POST":
send_mail('Subject here', 'Here is the message.', '[email protected]', ['[email protected]'], fail_silently=False)
print request.POST
return render_to_response(template_name, { 'form': form }, context_instance=RequestContext(request))
What is going wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定表单已提交吗?因为如果您提交一个带有 debug true 的表单,并且表单中不存在 csrf 令牌,Django 应该会给出错误。另一个想法;您正在与 smtp.gmail.com 通话,但使用 @googlemail.com 地址。你确定能应付吗?
编辑
我做了不同的事情;我没有使用现有的应用程序,而是构建了一个新的应用程序。我的应用程序需要做的不仅仅是邮寄。而且它只有两个文件,所以应该有帮助。我也使用过 gmail,另一个优点:) 我会给你相关的代码,但是请注意;)
settings.py:
和应用程序,app/views.py
请注意,你真的需要有 {% csrf_token %} 在您的表单中。在这种情况下,您必须自己构建表单模板。让我知道这是否有帮助。
Are you sure the form even submits? Because if you submit a form with debug true, and no csrf token present in your form, Django should give an error. Another idea; you're talking to smtp.gmail.com, but use an @googlemail.com address. Are you sure that copes?
EDIT
I did this different; instead of using an existing app I build a new one. My app needed to do more than just mailing. And it's only two files, so that should help. I used gmail too, another plus:) I'll give you the relevant code, but cut peaces out, so watch that;)
settings.py:
and the app, app/views.py
Note that you REALLY NEED to have {% csrf_token %} inside your form. The form template you'll have to build yourself in this case. Let me know if this helped.
确保 settings.py 中的 ADMIN、MANAGERS 设置可用,因为它会
再次在 contact_form 的 forms.py 中
查找这些电子邮件确保在 settings.py 中设置电子邮件端口主机设置
make sure your ADMIN,MANAGERS settings in your settings.py is available because it's lookin for these emails
in forms.py of contact_form
again make sure you set email port host setting in yout settings.py