def send_activation_email(self): """ Sends a activation email to the user. This email is send when the user wants to activate their newly created user. """ context = {'user': self.user, 'without_usernames': settings.BAPH_AUTH_WITHOUT_USERNAMES, 'protocol': get_protocol(), 'activation_days': settings.BAPH_ACTIVATION_DAYS, 'activation_key': self.activation_key, 'org': Organization.get_current(), } subject = render_to_string('registration/emails/activation_email_subject.txt', context) subject = ''.join(subject.splitlines()) message = render_to_string('registration/emails/activation_email_message.txt', context) send_mail(subject, message, django_settings.DEFAULT_FROM_EMAIL, [self.user.email, ])
def send_confirmation_email(self): """ Sends an email to confirm the new email address. This method sends out two emails. One to the new email address that contains the ``email_confirmation_key`` which is used to verify this this email address with :func:`UserenaUser.objects.confirm_email`. The other email is to the old email address to let the user know that a request is made to change this email address. """ context = {'user': self.user, 'without_usernames': settings.BAPH_AUTH_WITHOUT_USERNAMES, 'new_email': self.email_unconfirmed, 'protocol': get_protocol(), 'confirmation_key': self.email_confirmation_key, 'org': Organization.get_current(), } # Email to the old address, if present subject_old = render_to_string( 'registration/emails/confirmation_email_subject_old.txt', context) subject_old = ''.join(subject_old.splitlines()) message_old = render_to_string( 'registration/emails/confirmation_email_message_old.txt', context) if self.user.email: send_mail(subject_old, message_old, django_settings.DEFAULT_FROM_EMAIL, [self.user.email]) # Email to the new address subject_new = render_to_string( 'registration/emails/confirmation_email_subject_new.txt', context) subject_new = ''.join(subject_new.splitlines()) message_new = render_to_string( 'registration/emails/confirmation_email_message_new.txt', context) send_mail(subject_new, message_new, django_settings.DEFAULT_FROM_EMAIL, [self.email_unconfirmed, ])
def save(self, domain_override=None, subject_template_name='registration/password_reset_subject.txt', email_template_name='registration/password_reset_email.html', use_https=False, token_generator=default_token_generator, from_email=None, request=None): '''Generates a one-use only link for resetting password and sends to the user. ''' from django.core.mail import send_mail for user in self.users_cache: if not user.has_usable_password(): continue if not domain_override: org = Organization.get_current() if isinstance(org, dict): site_name = org['name'] domain = org['host'] else: site_name = org.name domain = org.host else: site_name = domain = domain_override site_name =None 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', } subject = render_to_string(subject_template_name, \ RequestContext(request, c)) subject = ''.join(subject.splitlines()) email = render_to_string(email_template_name, \ RequestContext(request, c)) send_mail(subject, email, from_email, [user.email])