不要冻结发送邮件django [英] dont freeze on sending mail django
问题描述
当django发送电子邮件时,取决于smtp服务器,需要几毫秒到几秒钟。所以我所面临的问题是当django开始发送电子邮件时冻结在那里。用户必须等到邮件发送完毕。我想知道如果我可以简单地返回html页面,并且在后台可以发送电子邮件而不让用户等待。
When django sends an email, it takes from a few milli-seconds to a few seconds depending upon the smtp server. So the problem that i am facing is when django starts sending email it freezes there. The user would have to wait till the mail has been sent. I was wondering if i could simply return the html page and in the background the email could be sent without making the user wait for it.
骨架就在页面之前正在呈现,电子邮件正在发送。所以,我想首先渲染页面,然后在后台发送电子邮件。
skeleton is that right before the page is being rendered, email is being sent. So, I want to render the page first and then send the email in the background.
推荐答案
我已经做了这样的事情我的项目使用线程:
I have done something like this in my project that uses threads:
class EmailThread(Thread):
def __init__(self, myemail):
self.myemail = myemail
Thread.__init__(self)
def run(self):
self.myemail.send()
class MyEmailMessage(EmailMessage):
def send_async(self, fail_silently=False):
thread = EmailThread(self)
thread.start()
# send email
email = MyEmailMessage(...)
email.send_async()
这篇关于不要冻结发送邮件django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!