Python/Django: sending emails in the background

最后都变了- 提交于 2019-12-02 23:08:08

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.

Another option is django-mailer. It queues up mail in a database table and then you use a cron job to send them.

https://github.com/pinax/django-mailer

A thread may be a possible solution. I use threads intensively in my application for haevy tasks.

# 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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!