太陽底下沒有新鮮事,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>')