def send_by_email(request, object_info): if FORCE_AJAX and not request.is_ajax(): raise Http404('This page is only reachable by Ajax request. Forced by SEND_BY_EMAIL_FORCE_AJAX setting.') context = {} object = object_info['object'] if request.method == 'POST': form = SendMailForm(request.POST) if form.is_valid(): cd = form.cleaned_data subject = u'%s %s' % (settings.EMAIL_SUBJECT_PREFIX, _('link to `%s`') % unicode(object)) message = render_to_string('send_email/email.html', { 'sender': cd['sender'], 'message': cd['message'], 'site': Site.objects.get_current(), 'url': request.build_absolute_uri(object.get_absolute_url()) }) recipients = (form.cleaned_data['recipient'],) send_mail(subject, message, settings.SERVER_EMAIL, recipients, fail_silently=False) publishable_email_sent.send(sender=object, subject=subject, message=message, recipients=recipients) if request.is_ajax(): return send_by_email_success(request, object_info) else: return HttpResponseRedirect(resolver.reverse(object, 'send_by_email_success')) else: form = SendMailForm() context['form'] = form context.update(object_info) return render_to_response('send_email/form.html', context, context_instance=RequestContext(request))
def test_form(request): if request.method == 'POST': form = SendMailForm(request.POST) if form.is_valid(): print 'process' else: form = SendMailForm() template_vars = {} template_vars['form'] = form return render_to_response('testForm.html', template_vars, context_instance=RequestContext(request))
def rating_send_mail(request): if request.POST: form = SendMailForm(request.POST) if form.is_valid(): data = form.cleaned_data rating_id = data.get('rating_id') rating = Rating.objects.get(pk=rating_id) subject = data.get('subject') body = data.get('body') rating.author.email_user(subject, body, FROM_EMAIL) #to_email = rating.author.email #send_mail(subject, body, FROM_EMAIL, [TO_EMAIL], False, "", "") return HttpResponseRedirect(reverse('ratings4you.views_admin.moderate_rating', kwargs={"id":rating_id}))