Search code examples
pythondjangodjango-registration

send activate-email with django-registration


I am curious if there's a way to send activated email with username, password by using django-registration. First I thought about modifying registration form but I need some example.


Solution

  • django-registration uses the following code, internally, to handle sending emails:

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

    If you want to work, you will have to specify the value DEFAULT_FROM_EMAIL in your settings.py.

    Also, note the following:

    Mail is sent using the SMTP host and port specified in the EMAIL_HOST and EMAIL_PORT settings. The EMAIL_HOST_USER and EMAIL_HOST_PASSWORD settings, if set, are used to authenticate to the SMTP server, and the EMAIL_USE_TLS setting controls whether a secure connection is used.

    So, to give an example, here's what I've used in a settings.py file to use a gmail account:

    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = 465
    EMAIL_USE_TLS = True
    
    EMAIL_HOST_USER = 'my@gmail.com'
    EMAIL_HOST_PASSWORD = 'my_emails_password'
    

    django-registration should then be able to send emails.