Skip to content

Commit d0b5e7c

Browse files
committed
refactor: 使用多线程发送订阅邮件。
1 parent 0524b0a commit d0b5e7c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

hexoweb/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def send_email(request):
936936
email_passd = SettingModel.objects.get(name="EMAIL_HOST_PASSWORD").content
937937
html_content = getSubscribeHtml()
938938
for to_email in MailModel.objects.all():
939-
send_custom_email(to_email.mail, to_email.name, from_email, email_passd, html_content, 'html')
939+
SendMail(to_email.mail, to_email.name, from_email, email_passd, html_content, 'html').start()
940940
return JsonResponse(safe=False, data={"msg":"OK,邮件已经发送完成。", "status":"true"})
941941

942942
# 保存点赞位

hexoweb/functions.py

+21
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from bs4 import BeautifulSoup
4141
from html import escape
4242
import logging
43+
import threading
4344

4445
disable_warnings()
4546

@@ -996,6 +997,26 @@ def send_custom_email(rev_mail, rev_name, from_email, email_passd, content, cont
996997
msg.content_subtype = content_subtype
997998
msg.send()
998999

1000+
class SendMail(threading.Thread):
1001+
def __init__(self,rev_mail, rev_name, from_email, email_passd, content, content_subtype):
1002+
self.rev_mail = rev_mail
1003+
self.rev_name = rev_name
1004+
self.from_email = from_email
1005+
self.email_passd = email_passd
1006+
self.content = content
1007+
self.content_subtype = content_subtype
1008+
threading.Thread.__init__(self)
1009+
1010+
def run(self):
1011+
send_custom_email(
1012+
self.rev_mail,
1013+
self.rev_name,
1014+
self.from_email,
1015+
self.email_passd,
1016+
self.content,
1017+
self.content_subtype
1018+
)
1019+
9991020
# print(" ......................阿弥陀佛......................\n" +
10001021
# " _oo0oo_ \n" +
10011022
# " o8888888o \n" +

0 commit comments

Comments
 (0)