gpt4 book ai didi

python - 如何使用 django 发送异步电子邮件

转载 作者:IT老高 更新时间:2023-10-28 21:07:42 27 4
gpt4 key购买 nike

这是我的代码:

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()

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

最佳答案

现在好了;

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()

关于python - 如何使用 django 发送异步电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4447081/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com