Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 433
Asinox Avatar asked Aug 25 '09 04:08

Asinox


People also ask

How can I send mail after registration in Django?

Then we used the EmailMessage() function to send mail along with the subject, message. Email message create by a template. This template create an email body with activate link that will send for application. Now we need to create a view for the activation link.


2 Answers

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', '[email protected]', '[email protected]'
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()
like image 59
Paul Tarjan Avatar answered Oct 07 '22 08:10

Paul Tarjan


I know this is old and the registration package is no longer maintained. Just in case somebody still wants this. The additional steps wrt to the answer of @bpierre are:
- subclass the RegistrationView, i.e. your app's views.py

class MyRegistrationView(RegistrationView):
...
def register(self, request, **cleaned_data):
    ...
    new_user = HtmlRegistrationProfile.objects.create_inactive_user(username, email, password, site)

- in your urls.py change the view to the sub-classed view, i.e. - List item

url(r'accounts/register/$', MyRegistrationView.as_view(form_class=RegistrationForm), name='registration_register'),'
like image 25
Bernd Jerzyna Avatar answered Oct 07 '22 09:10

Bernd Jerzyna