Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-registration - Sending Email in a asynchronous way

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 = '[email protected]'
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.

like image 846
Valdir Stumm Junior Avatar asked Aug 14 '12 16:08

Valdir Stumm Junior


People also ask

How do I send an email in Django after registering?

Configure Settings First we need to configure the email host server in the settings.py for confirmation mail. Add the below configuration in the settings.py file. We used the email-id along with the password and gmail SMTP host server. You can use the other SMTP server as well.

Can Django be asynchronous?

Latest version of the popular Python web framework also provides an asynchronous interface for all data access operations. Django 4.1, a new version of the major Python-based web framework, adds capabilities such as asynchronous handlers and an ORM interface but also makes some backward-incompatible changes.

How do I send an automatic email in Django?

Sending Emails with the Django ShellWe import the Django send_mail function. Then we import the settings object which contains all the global settings and the per-site settings (those inside the settings.py file). Finally, we pass all the needed arguments to the send_mail function.


1 Answers

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> )
like image 62
Pratik Mandrekar Avatar answered Oct 04 '22 17:10

Pratik Mandrekar