示例#1
0
def new_message_email(sender, instance, signal,
                      subject_prefix=_(u'New Message: %(subject)s'),
                      template_name="messages/new_message.html",
                      default_protocol=None,
                      *args, **kwargs):
    """
    This function sends an email and is called via Django's signal framework.
    Optional arguments:
        ``template_name``: the template to use
        ``subject_prefix``: prefix for the email subject.
        ``default_protocol``: default protocol in site URL passed to template
    """
    if default_protocol is None:
        default_protocol = getattr(settings, 'DEFAULT_HTTP_PROTOCOL', 'http')

    if 'created' in kwargs and kwargs['created']:
        try:
            current_domain = Site.objects.get_current().domain
            subject = subject_prefix % {'subject': instance.subject}
            ctx = {
                'site_url': '%s://%s' % (default_protocol, current_domain),
            }
            if instance.recipient.email != "":
                Notification.send(template="new_message",
                                  subject=subject,
                                  ctx=ctx,
                                  recipients=[instance.recipient.email, ],
                                  sent_from=settings.DEFAULT_FROM_EMAIL)

        except Exception, e:
            pass #fail silently
示例#2
0
def new_follower(user, target, instance, **kwargs):
    try:
        current_domain = Site.objects.get_current().domain
        ctx = {"site_url": "%s://%s" % ("http", current_domain), "user": target.user, "follower": user}

        print target.user.email
        if target.user.email:
            Notification.send(
                template="new_follower", recipients=[target.user.email], sent_from=settings.DEFAULT_FROM_EMAIL, ctx=ctx
            )

    except Exception, e:
        pass  # fail silently
示例#3
0
    def send_inivitation(self, request, name_or_email):
        if not self.pk:
            self.save()

        if '@' in name_or_email:
            user = User.objects.filter(email=name_or_email)[:1]
            if user:
                user = user[0]
            else:
                return False
        else:
            first_name, last_name = tuple([name.lower() for name in name_or_email.split()])
            user = User.objects.filter(first_name__icontains=first_name, last_name__icontains=last_name)[:1]
            if user: user = user[0]

        user_group, created = UserGroup.objects.get_or_create(user=user, group=self)
        #        if user_group.invitation_accepted:
        #            return False

        user_group.generate_secret_code()
        user_group.invitation_accepted = False
        user_group.save()
        #        current_site = Site.objects.get_current()

        #        send_mail('Group Invitation',
        #                  """
        #                      You have a group invitation from %s
        #                      Accept this by clicking on http://%/group/accept/%s
        #
        #                  """ % (self.user.get_profile.get_pretty_name(), current_site.domain, user_group.invitation_code),
        #                  '*****@*****.**',
        #                  [user.email,], fail_silently=False)

        Notification.send(template="group_invite", recipients=[user.email, ],
                          ctx={'group': self, 'user_group': user_group, 'user': user})

        return True
示例#4
0
    def save(self, domain_override=None, email_template_name='account/reset_email.html', subject_template_name=None,
             use_https=False, token_generator=default_token_generator, from_email=None, request=None):

        from django.core.mail import EmailMultiAlternatives

        for user in self.users_cache:
            if not domain_override:
                current_site = get_current_site(request)
                site_name = current_site.name
                domain = current_site.domain
            else:
                site_name = domain = domain_override

            c = {
                'email': user.email,
                'domain': domain,
                'site_name': site_name,
                'uid': int_to_base36(user.id),
                'user': user,
                'token': token_generator.make_token(user),
                'protocol': use_https and 'https' or 'http',
            }

            Notification.send(recipients=[user.email, ], template='password_reset', ctx=c)