from django.core.mail import send_mail as core_send_mail
from django.core.mail import EmailMultiAlternatives
import threading
class EmailThread(threading.Thread):
def __init__(self, subject, body, from_email, recipient_list, fail_silently, html):
self.subject = subject
self.body = body
self.recipient_list = recipient_list
self.from_email = from_email
self.fail_silently = fail_silently
self.html = html
threading.Thread.__init__(self)
def run (self):
msg = EmailMultiAlternatives(self.subject, self.body, self.from_email, self.recipient_list)
if self.html:
msg.attach_alternative(self.html, "text/html")
msg.send(self.fail_silently)
def send_mail(subject, body, from_email, recipient_list, fail_silently=False, html=None, *args, **kwargs):
EmailThread(subject, body, from_email, recipient_list, fail_silently, html).start()
https://djangosnippets.org/snippets/1982/
django多线程发邮件
最新推荐文章于 2020-11-25 19:38:47 发布