Last active
April 6, 2023 05:05
Revisions
-
Alexandr Shurigin revised this gist
Jul 3, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ ## Simplest Async Email Backend for Django ### What is this? It is simplest email backend for Django which supports async email delivery in parallel threads. Keep it simple! It has various analogs, you can google for it yourself. -
Alexandr Shurigin revised this gist
Jul 3, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ ### What is this? It is simplest email backend for Django which supports async email delivery in parallel threads. Keep it simple! It has various analogs, you can google for it yourself. ### Requirements -
Alexandr Shurigin created this gist
Jul 3, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ ### What is this? It is simple, fast and clean Django's email backend which supports async sending of emails in parallel threads. Keep it simple! It has various analogs, you can google for it yourself. ### Requirements Django async email backend requires futures library. So you need to install it with `pip install futures`. ### Django configuration settings This is simple backend so you need to configure django to use our backend and you can alter pool size with `EMAIL_BACKEND_POOL_SIZE`. ``` python EMAIL_BACKEND = 'utils.email.EmailBackend' EMAIL_BACKEND_POOL_SIZE = 15 # default value ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ from concurrent import futures from django.conf import settings from django.core.mail.backends.smtp import EmailBackend as BaseEmailBackend class EmailBackend(BaseEmailBackend): """ A wrapper that manages the SMTP network connection asynchronously """ def __init__(self, *args, **kwargs): super(EmailBackend, self).__init__(*args, **kwargs) self.executor = futures.ThreadPoolExecutor( max_workers=int(getattr(settings, 'EMAIL_BACKEND_POOL_SIZE', 15)) ) def send_messages(self, email_messages): return self.executor.submit(super(EmailBackend, self).send_messages, email_messages)