如何使用Django发送异步电子邮件

发布于 2021-01-29 15:08:13

这是我的代码:

class EmailThread(threading.Thread):
    def __init__(self, subject, html_content, recipient_list):
        self.subject = subject
        self.recipient_list = recipient_list
        self.html_content = html_content
        threading.Thread.__init__(self)

    def run (self):
        msg = EmailMultiAlternatives(self.subject, self.html_content, EMAIL_HOST_USER, self.recipient_list)
        #if self.html_content:
        msg.attach_alternative(True, "text/html")
        msg.send()

def send_mail(subject, html_content, recipient_list):
    EmailThread(subject, html_content, recipient_list).start()

它不发送电子邮件。我能做什么?

关注者
0
被浏览
242
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    现在还好;

    import threading
    from threading import Thread
    
    class EmailThread(threading.Thread):
        def __init__(self, subject, html_content, recipient_list):
            self.subject = subject
            self.recipient_list = recipient_list
            self.html_content = html_content
            threading.Thread.__init__(self)
    
        def run (self):
            msg = EmailMessage(self.subject, self.html_content, EMAIL_HOST_USER, self.recipient_list)
            msg.content_subtype = "html"
            msg.send()
    
    def send_html_mail(subject, html_content, recipient_list):
        EmailThread(subject, html_content, recipient_list).start()
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看