6

So, I'm using django-registration in my project to enable user self-registration in the app I'm building. I've configured django-registration to send confirmation emails to the registered users.

My settings.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myUser@myCompany.com'
EMAIL_HOST_PASSWORD = 'apassword'
...
ACCOUNT_ACTIVATION_DAYS = 7

But, after the user fills the registration form and clicks the register button, the page keeps waiting for the email sending process. It looks like the response (the confirmation page) is received only after the email has been sent.

I've read another thread that shows how to send an email in a thread. Is there a way to send emails, using django-registration, in such a way that the response for the form registration submit doesn't keep blocked until the email is sent? I mean, I don't want to modify the django-registration itself.

Community
  • 1
  • 1
Valdir Stumm Junior
  • 4,568
  • 1
  • 23
  • 31

1 Answers1

4

You should make use of Django Mailer to queue the sending of emails.

Alternatively you could use Celery with Django to queue up your emails to the SMTP server or use Amazon SES

from registration.signals import user_activated, user_registered

user_registered.connect(<Hook your add email to celery task queue> )
Pratik Mandrekar
  • 9,362
  • 4
  • 45
  • 65
  • It looks like, to use Django Mailer, I'll need to modify the send_mail import at django-registration, am I right? – Valdir Stumm Junior Aug 14 '12 at 18:00
  • 1
    Yes. See https://bitbucket.org/seanoc/django-registration/src/35091bf234e9/registration/models.py 'if send_email: if "mailer" in settings.INSTALLED_APPS: from mailer import send_mail else: from django.core.mail import send_mail' – Pratik Mandrekar Aug 14 '12 at 18:13