用django发送异步邮件

太阳底下没有新鲜事,github是一个神奇的地方,你有什么想法,需求,点子。其实别人早就想到,而且也已经做到。

所以不要高估自己,有什么想法还是GITHUB一下,免得成了井底之娃。

这几天一直在研究python的异步发送邮件问题,django , flask 之流都是同步框架,处理IO,发送电子邮件这种耗时的操作,就有点蛋痛了。

由于基础知识不扎实,自行研究了Asyncio之流无果,在github上无赖的输入了asyn django sendmail 搜索了一把。居然找到了别人已经封闭好的源代码。

不敢独享:https://github.com/ui/django_asynchronous_send_mail

按照之前我写的日志方法(利用django.core.mail发送QQ邮件的配置)配置好django发送邮件信息后,导入此源码包。零延迟发送邮件成功。

from asynchronous_send_mail import send_mail

send_mail('Subject here', 'Here is the message.', 'from@example.com', ['to@example.com'], fail_silently=False) 

send_mail('Subject here', 'Here is the message.', 'from@example.com', ['to@example.com'], fail_silently=False, html = '<HTML_TEXT_HERE>')

  

原文地址:https://www.cnblogs.com/draculaqk/p/8025083.html