Найти - Пользователи
Полная версия: Оправить мейл
Начало » Django » Оправить мейл
1
Mutagena
Тривиальный вопрос. Каким образом мне отправить емейл?
В файле forms.py:
class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField()
message = forms.CharField(widget=forms.Textarea)
В views.py:
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
#отправка мейла. нужна помощь именно с этой строкой
else:
form = ContactForm()
return render_to_response('core/contact.html',
{'form': form,},
context_instance=RequestContext(request))
expee
http://www.yak.net/fqa/84.html

ps. покажешь потом то чудо, которое разрабатываешь? :)
Mutagena
expee, покажу на работающем примере )
Mutagena
expee, пишу как в примере
server = smtplib.SMTP('localhost')
server.sendmail(cd['subject'], 'mutagena@gmail.com', cd['message'])
server.quit()
возникает ошибка. Вот трейсбек:
Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/contact/
Django Version: 1.1.1
Python Version: 2.6.3
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'totalcontrol.core',
'django.contrib.comments']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "C:\Documents and Settings\Mutagena\workspace\totalcontrol\..\totalcontrol\core\views.py" in contact
144. server = smtplib.SMTP('localhost')
File "C:\Python26\lib\smtplib.py" in __init__
239. (code, msg) = self.connect(host, port)
File "C:\Python26\lib\smtplib.py" in connect
295. self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python26\lib\smtplib.py" in _get_socket
273. return socket.create_connection((port, host), timeout)
File "C:\Python26\lib\socket.py" in create_connection
514. raise error, msg

Exception Type: error at /contact/
Exception Value: (10061, '\xcf\xee\xe4\xea\xeb\xfe\xf7\xe5\xed\xe8\xe5 \xed\xe5 \xf3\xf1\xf2\xe0\xed\xee\xe2\xeb\xe5\xed\xee,')
expee
Собственно в ошибке пишется, что подключение не установлено :) SMTP-сервер настроен? Если нет, то в гугл и настраиваем. Можешь еще попробовать с sendmail (пример все там же)
Mutagena
expee, ну если так, то понадеюсь, что на хостинге будет работать.
expee
На хостинге тебе должны дать (если есть услуга такая) все данные о smtp-сервере.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB