示例#1
0
    def sendmail(self, request, form_url=None, extra_content=None):
        if request.method == "POST":
            form = MessageForm(request.POST)
            if form.is_valid():
                from djpostman.sender import render_to_send_multi_mail

                recipient_list = form.cleaned_data["recipients_email"] + [
                    u.email for u in form.cleaned_data["recipients"]
                ]
                subject = form.cleaned_data["subject"]

                render_to_send_multi_mail(
                    subject=subject,
                    template="mail/manual_mail.html",
                    context={
                        "text": form.cleaned_data["text"],
                        "use_greeting": form.cleaned_data["use_greeting"],
                        "user": request.user.get_full_name() or request.user,
                    },
                    recipient_list=recipient_list,
                )

                messages.success(
                    request, _(u"Das Email '%s' wurde an '%s' versendet") % (subject, ",".join(recipient_list))
                )
                return redirect("admin:djpostman_message_changelist")
        else:
            form = MessageForm()
        return TemplateResponse(request, "admin/djpostman/sendmail_form.html", {"form": form})
 def send_confirmation(self, email_address):
     salt = sha_constructor(str(random())).hexdigest()[:5]
     confirmation_key = sha_constructor(salt + email_address.email).hexdigest()
     current_site = Site.objects.get_current()
     # check for the url with the dotted view path
     try:
         path = reverse("emailconfirmation.views.confirm_email",
             args=[confirmation_key])
     except NoReverseMatch:
         # or get path with named urlconf instead
         path = reverse(
             "emailconfirmation_confirm_email", args=[confirmation_key])
     protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http")
     activate_url = u"%s://%s%s" % (
         protocol,
         unicode(current_site.domain),
         path
     )
     
     user = email_address.user
     context = {
         "user_name": user.get_full_name() or  user.username,
         "activate_url": activate_url,
         "current_site": current_site,
         "confirmation_key": confirmation_key,
     }
     subject = render_to_string(
         "emailconfirmation/email_confirmation_subject.txt", context)
     
     render_to_send_multi_mail(
         # remove superfluous line breaks
         "".join(subject.splitlines()), 
         "emailconfirmation/email_confirmation_message.html",
         context,
         [email_address.email]
     )
     
     confirmation = self.create(
         email_address=email_address,
         sent=datetime.datetime.now(),
         confirmation_key=confirmation_key
     )
     email_confirmation_sent.send(
         sender=self.model,
         confirmation=confirmation,
     )
     return confirmation