Created
November 13, 2013 03:00
-
-
Save fermayo/7442963 to your computer and use it in GitHub Desktop.
Extend django-registration to send HTML emails for activation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HtmlRegistrationProfile(RegistrationProfile): | |
class Meta: | |
proxy = True | |
def send_activation_email(self, site): | |
"""Send the activation mail""" | |
from django.core.mail import EmailMultiAlternatives | |
from django.template.loader import render_to_string | |
ctx_dict = {'activation_key': self.activation_key, | |
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, | |
'site': site} | |
subject = render_to_string('registration/activation_email_subject.txt', | |
ctx_dict) | |
# Email subject *must not* contain newlines | |
subject = ''.join(subject.splitlines()) | |
message_text = render_to_string('registration/activation_email.txt', ctx_dict) | |
message_html = render_to_string('registration/activation_email.html', ctx_dict) | |
msg = EmailMultiAlternatives(subject, message_text, settings.DEFAULT_FROM_EMAIL, [self.user.email]) | |
msg.attach_alternative(message_html, "text/html") | |
msg.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment