from django.conf import settings from django.contrib.auth.models import User from django.contrib.sites.shortcuts import get_current_site from django.core.mail import EmailMessage, send_mail, mail_admins from django.template.loader import render_to_string from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_encode from . tokens import generate_token from users import parameter def send_activation_mail(new_user, request): email_subject = "Activate Account" message2 = render_to_string('users/email_activation.html', { 'name': new_user.first_name, 'base_url': request.build_absolute_uri('/')[:-1], 'pk': new_user.pk, }) email = EmailMessage( email_subject, message2, settings.EMAIL_HOST_USER, ) mail_admins(email_subject, message2, fail_silently=True) def send_validation_failed(uid, token): subject = "E-Mail validation failed!" message = f"uid = {uid}\ntoken = '{token}'" mail_admins(subject, message, fail_silently=True) def send_welcome_mail(new_user: User): subject = "Welcome!" message = """Hello %(username)s. Welcome! Thank you for registration.""" % {"username": new_user.first_name} message += "\n\n" + parameter.registration_flow_description(new_user.username) send_mail(subject, message, settings.EMAIL_FROM, [new_user.email], fail_silently=True) def send_validation_mail(new_user, request): email_subject = "Confirm your Email" message2 = render_to_string('users/email_confirmation.html', { 'name': new_user.first_name, 'base_url': request.build_absolute_uri('/')[:-1], 'uid': urlsafe_base64_encode(force_bytes(new_user.pk)), 'token': generate_token.make_token(new_user) }) email = EmailMessage( email_subject, message2, settings.EMAIL_HOST_USER, [new_user.email], ) send_mail(email_subject, message2, settings.EMAIL_FROM, [new_user.email], fail_silently=True)