Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Yogendra0Sharma/c9da569ce77a70293a2c13c8d78e3ebc to your computer and use it in GitHub Desktop.
Save Yogendra0Sharma/c9da569ce77a70293a2c13c8d78e3ebc to your computer and use it in GitHub Desktop.
Avoid noticeable page-load slowdown when sending emails with django-allauth by sending email in background
import threading
from allauth.account.adapter import DefaultAccountAdapter
class BackgroundEmailSendingAccountAdapter(DefaultAccountAdapter):
def send_mail(self, template_prefix, email, context):
mailing_thread = threading.Thread(
target=super(BackgroundEmailSendingAccountAdapter, self).send_mail,
args=(template_prefix, email, context)
)
mailing_thread.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment