Skip to content

Instantly share code, notes, and snippets.

@rfj001
Created August 16, 2016 16:30
Show Gist options
  • Save rfj001/b762bdb2dcf52c3ab315ef3cbbb739e8 to your computer and use it in GitHub Desktop.
Save rfj001/b762bdb2dcf52c3ab315ef3cbbb739e8 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