2011-01-06 5 views
1

Ich habe diese django-contact-form App installiert. Wenn ich per Kontaktformular eine E-Mail an mein Google Mail-Konto senden möchte, erhalte ich keinen Fehler und werde zu meiner contact_form_sent.html weitergeleitet, aber es wird keine E-Mail gesendet. Kann mir jemand bei der Fehlersuche helfen? Ist das ein Problem des SMTP-Servers, weil ich von localhost aus teste ???Mail wird nicht von Django-Kontaktformular App gesendet und es gibt keine Fehlermeldung

Meine Konfigurationen sind wie folgt, es Patrick Beeson's ähnelt:

settings.py Ich habe bereits andere E-Mail-Konten und deren sachgemäßer Ports geprüft.

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

wenn action="." in meinem contact_form.html Einstellung und das Hinzufügen von print request.POST bekomme ich diese in meinem Entwicklung ent-Server auf localhost, nach dem Klick auf 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'[email protected] 
com']}> 

EDITED

Wenn ich meine eigene view.py schreiben bekomme ich diesen Fehler:

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

meine neue eigene views.py sieht so aus:

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

Was läuft hier falsch?

Antwort

0

Sind Sie sicher, dass das Formular sogar übermittelt wird? Wenn Sie ein Formular mit debug true und keinem csrf-Token in Ihrem Formular übergeben, sollte Django einen Fehler anzeigen. Eine andere Idee; Sie sprechen mit smtp.gmail.com, aber verwenden Sie eine @ googlemail.com-Adresse. Bist du sicher, dass das bewältigt?

BEARBEITEN

Ich tat das anders; Anstatt eine vorhandene App zu verwenden, baue ich eine neue. Meine App musste mehr tun als nur Mailing. Und es sind nur zwei Dateien, also sollte das helfen.Früher habe ich auch gmail, ein weiteres Plus :) Ich werde Sie den entsprechenden Code geben, aber peaces herausgeschnitten, so sehen, dass;)

settings.py:

from local import localsettings 

DEBUG = True 
TEMPLATE_DEBUG = DEBUG 

ADMINS = (
    ('Jasper Kennis', '[email protected]'), 
) 

MANAGERS = ADMINS 

DATABASES = { 
    'default': { 
     'ENGINE': localsettings.db_engine, 
     'NAME': localsettings.db_name, 
     'USER': '', 
     'PASSWORD': '', 
     'HOST': '', 
     'PORT': '', 
    } 
} 

SITE_ID = 1 

# If you set this to False, Django will make some optimizations so as not 
# to load the internationalization machinery. 
USE_I18N = True 

# If you set this to False, Django will not format dates, numbers and 
# calendars according to the current locale 
USE_L10N = True 

# Make this unique, and don't share it with anybody. 
SECRET_KEY = '###' 

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
) 


INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.admin', 
     'therelevantapp', 
) 


EMAIL_USE_TLS = True 
EMAIL_HOST = 'smtp.gmail.com' 
EMAIL_HOST_USER = '###@gmail.com' 
EMAIL_HOST_PASSWORD = '###' 
EMAIL_PORT = 587 

und die app, app/views Py

import os 
import os.path 
import string 
from random import choice 

from app.models import * 
from TitelGenerator.TitelGenerator import TitelGenerator 
from django import forms 
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 django.core.mail import EmailMultiAlternatives 



def klaar(request): 
    if request.method == "POST": 
     title = 'Je inschrijving is voltooid!' 
     message = 'a whole message' 
     send_mail(title , message , 'sendermail' , 'receivermail' ,  fail_silently=False) 

     return render_to_response('klaar.html' , { 'titel': kind.id, 'request':  request.FILES }, context_instance = RequestContext(request)) 

Beachten Sie, dass Sie wirklich haben müssen {% csrf_token%} in Ihrem Formular. Die Formularvorlage müssen Sie in diesem Fall selbst erstellen. Lass es mich wissen, wenn das hilft.

+0

Ich habe es mit smtp.googlemail.com getestet, aber immer noch das gleiche Problem. Gibt es eine Möglichkeit zum Debuggen? – saeed

+0

Ich weiß, ich hatte einmal ähnliche Probleme. Ich hoffe, ich habe das Repo noch irgendwo, lass mich nach dir Ausschau halten. –

+0

Ich würde jede Hilfe schätzen, weil ich verrückt werde, ohne dass eine Fehlermeldung ausgegeben wird. Es ist wie ein Ratespiel. – saeed

0

stellen Sie sicher, Ihre ADMIN, MANAGER Einstellungen in Ihrem settings.py ist verfügbar, da es für diese E-Mails

in forms.py von CONTACT_FORM schau ist

class BaseEmailFormMixin(object): 
    from_email = settings.DEFAULT_FROM_EMAIL 
    recipient_list = [email for _, email in settings.MANAGERS] 

wieder sicherstellen, dass Sie E-Mail-Anschluss Host-Einstellung eingestellt in yout settings.py

EMAIL_HOST = 'yourmailserver' 
EMAIL_PORT = "587" 
EMAIL_HOST_USER = '' 
EMAIL_HOST_PASSWORD = '' 
EMAIL_USE_TLS = True