diff --git a/allianceauth/authentication/templates/registration/activation_email.txt b/allianceauth/authentication/templates/registration/activation_email.txt index 028fbd2b..d303bf16 100644 --- a/allianceauth/authentication/templates/registration/activation_email.txt +++ b/allianceauth/authentication/templates/registration/activation_email.txt @@ -2,10 +2,6 @@ You're receiving this email because someone has entered this email address while If this was you, please click on the link below to confirm your email address: -Confirm email address - -Link not working? Try copy/pasting this URL into your browser: - {{ scheme }}://{{ url }} This link will expire in {{ expiration_days }} day(s). diff --git a/allianceauth/authentication/templates/registration/activation_email_html.txt b/allianceauth/authentication/templates/registration/activation_email_html.txt new file mode 100644 index 00000000..907f2db9 --- /dev/null +++ b/allianceauth/authentication/templates/registration/activation_email_html.txt @@ -0,0 +1,19 @@ +

+ You're receiving this email because someone has entered this email address while registering for an account on {{ site.domain }} +

+ +

+ If this was you, please click on the link below to confirm your email address: +

+ +

+ Confirm email address +

+ +

+ This link will expire in {{ expiration_days }} day(s). +

+ +

+ If this was not you, it is safe to ignore this email. +

diff --git a/allianceauth/authentication/views.py b/allianceauth/authentication/views.py index e4331b8c..779f9a1c 100644 --- a/allianceauth/authentication/views.py +++ b/allianceauth/authentication/views.py @@ -6,8 +6,10 @@ from django.contrib.auth import login, authenticate from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.core import signing +from django.core.mail import EmailMultiAlternatives from django.http import JsonResponse from django.shortcuts import redirect, render +from django.template.loader import render_to_string from django.urls import reverse, reverse_lazy from django.utils.translation import gettext_lazy as _ @@ -137,9 +139,52 @@ class RegistrationView(BaseRegistrationView): form_class = RegistrationForm template_name = "public/register.html" email_body_template = "registration/activation_email.txt" + email_body_template_html = "registration/activation_email_html.txt" email_subject_template = "registration/activation_email_subject.txt" success_url = reverse_lazy('registration_complete') + def send_activation_email(self, user): + """ + Implement our own way to send a mail to make sure we + send a RFC conform multipart email + :param user: + :type user: + """ + + activation_key = self.get_activation_key(user) + context = self.get_email_context(activation_key) + context["user"] = user + + # email subject + subject = render_to_string( + template_name=self.email_subject_template, + context=context, + request=self.request, + ) + subject = "".join(subject.splitlines()) + + # plaintext email body part + message = render_to_string( + template_name=self.email_body_template, + context=context, + request=self.request, + ) + + # html email body part + message_html = render_to_string( + template_name=self.email_body_template_html, + context=context, + request=self.request, + ) + + # send it + user.email_user( + subject, + message, + settings.DEFAULT_FROM_EMAIL, + **{'html_message': message_html}, + ) + def get_success_url(self, user): if not getattr(settings, 'REGISTRATION_VERIFY_EMAIL', True): return reverse_lazy('authentication:dashboard')