def send_email_change_verification(self, request): """Send a verification email to the new email address""" user = self.user context = { "user": user, "validation_link": reverse( "user:validate_email_change", kwargs={ "uidb64": urlsafe_base64_encode(force_bytes(user.id)), "token": email_change_token.make_token(user), }, ), } subject = render_to_string( "userdb/email/user_email_change_verification_subject.txt", context).strip() html_content = render_to_string( "userdb/email/user_email_change_verification_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.new_email_pending_verification], html_message=html_content, fail_silently=False, )
def send_validation_link(self): user = self.user context = { "user": user, "validation_link": reverse( "user:validate_email", kwargs={ "uidb64": urlsafe_base64_encode(force_bytes(user.id)), "token": account_activation_token.make_token(user), }, ), } subject = render_to_string( "userdb/email/user_verification_subject.txt", context).strip() html_content = render_to_string( "userdb/email/user_verification_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.user.email], html_message=html_content, fail_silently=False, )
def send_lease_granted_email(self): context = {"server_lease_request": self} subject = render_to_string( "openstack/email/server_lease_request_granted_subject.txt", context, ).strip() html_content = render_to_string( "openstack/email/server_lease_request_granted_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.user.email], html_message=html_content, fail_silently=False, )
def send_team_licence_reminder_emails(self): """ Send team licence expiry reminder emails to primary and secondary users """ context = { "team": self, "team_management_url": f"/teams/{self.hashid}/team", # Vue route, can't use reverse "time_remaining": (self.licence_expiry - timezone.now()), "termination_date": self.licence_expiry + datetime.timedelta(days=settings.LICENCE_TERMINATION_DAYS), } # Email each team member for user in self.users.all(): context["user"] = user subject = render_to_string( "userdb/email/team_licence_reminder_subject.txt", context).strip() if user in self.admin_users.all(): html_content = render_to_string( "userdb/email/team_licence_reminder_primary_user_email.html", context, ) else: html_content = render_to_string( "userdb/email/team_licence_reminder_secondary_user_email.html", context, ) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [user.email], html_message=html_content, fail_silently=True, ) # Update team self.licence_last_reminder_sent_at = timezone.now() self.save()
def send_invitation_email(self): context = { "invitation": self, "url": reverse("user:accept_invitation", args=[self.uuid]), } subject = render_to_string("userdb/email/user_invite_subject.txt", context).strip() html_content = render_to_string("userdb/email/user_invite_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.email], html_message=html_content, fail_silently=False, )
def send_email_change_notification(self, request): """Send an email change notification to the existing/previous email address""" user = self.user context = { "user": user, } subject = render_to_string( "userdb/email/user_email_change_notification_subject.txt", context).strip() html_content = render_to_string( "userdb/email/user_email_change_notification_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.user.email], html_message=html_content, fail_silently=False, )
def verify_and_send_notification_email(self): """ Admin script: mark team as verified and notify the primary user """ context = {"user": self.owner, "team": self} subject = render_to_string( "userdb/email/notify_team_verified_subject.txt", context).strip() html_content = render_to_string( "userdb/email/notify_team_verified_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.owner.email], html_message=html_content, fail_silently=False, ) self.verified = True self.save()
def send_new_team_admin_email(self): """ Notify admin(s) of new team registration """ if not settings.NEW_REGISTRATION_ADMIN_EMAILS: return context = {"user": self.owner, "team": self} subject = render_to_string( "userdb/email/new_registration_admin_subject.txt", context).strip() html_content = render_to_string( "userdb/email/new_registration_admin_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, settings.NEW_REGISTRATION_ADMIN_EMAILS, html_message=html_content, fail_silently=True, )
def send_email_renewal_reminder(self): """Send an email renewal reminder for a server lease""" user = self.assigned_teammember.user context = { "user": user, "server_name": self.server_name, "server_management_url": f"/teams/{self.tenant.team.hashid}/servers", "renewal_url": self.renewal_url, "expiry": self.expiry, "days_remaining": self.time_remaining.days, "hours_remaining": self.time_remaining.days * 24 + self.time_remaining.seconds // 3600, } subject = render_to_string( "openstack/email/server_lease_expiry_reminder_subject.txt", context).strip() html_content = render_to_string( "openstack/email/server_lease_expiry_reminder_email.html", context) text_content = main_text_from_html(html_content) send_mail( subject, text_content, settings.DEFAULT_FROM_EMAIL, [user.email], html_message=html_content, fail_silently=False, ) self.last_reminder_sent_at = timezone.now() self.save()