25👍
✅
Use celery as a task queue and django-celery-email which is an Django e-mail backend that dispatches e-mail sending to a celery task.
7👍
Another option is django-mailer. It queues up mail in a database table and then you use a cron job to send them.
- Select Children of an Object With ForeignKey in Django?
- How can I automatically let syncdb add a column (no full migration needed)
5👍
If we are talking about to send only 20 mails time by time, a thread may be a possible solution. For expensive background tasks use Celery.
This is a sample using thread:
# This Python file uses the following encoding: utf-8
#threading
from threading import Thread
...
class afegeixThread(Thread):
def __init__ (self,usuari, parameter=None):
Thread.__init__(self)
self.parameter = parameter
...
def run(self):
errors = []
try:
if self.paramenter:
....
except Exception, e:
...
...
n = afegeixThread( 'p1' )
n.start()
Source:stackexchange.com