Search code examples
djangoemaildjango-templatesdjango-registration

django+ send email in html with django-registration


im using django-registration, all is fine, the confirmation email was sending in plain text, but know im fixed and is sending in html, but i have a litter problem... the html code is showing:

<a href="http://www.example.com/accounts/activate/46656b86eefc490baf4170134429d83068642139/">http://www. example.com/accounts/activate/46656b86eefc490baf4170134429d83068642139/</a>

and i dont need to show the html code like the ...

Any idea?

Thanks


Solution

  • I'd recommend sending both a text version and an html version. Look in the models.py of the django-registration for :

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])
    

    and instead do something like from the docs http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types

    from django.core.mail import EmailMultiAlternatives
    
    subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
    text_content = 'This is an important message.'
    html_content = '<p>This is an <strong>important</strong> message.</p>'
    msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
    msg.attach_alternative(html_content, "text/html")
    msg.send()