Skip to content

Commit 2446824

Browse files
committed
评论邮件创建线程发送
1 parent 21961fa commit 2446824

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

comments/models.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from blog.models import Article
55
from django.core.mail import EmailMultiAlternatives
66
from django.contrib.sites.models import Site
7+
import _thread
78

89

910
# Create your models here.
@@ -24,6 +25,9 @@ class Meta:
2425
verbose_name = "评论"
2526
verbose_name_plural = verbose_name
2627

28+
def send_comment_email(self, msg):
29+
msg.send()
30+
2731
def save(self, *args, **kwargs):
2832
super().save(*args, **kwargs)
2933
subject = '感谢您发表的评论'
@@ -43,8 +47,8 @@ def save(self, *args, **kwargs):
4347
msg = EmailMultiAlternatives(subject, html_content, from_email='no-reply@lylinux.net', to=[tomail])
4448

4549
msg.content_subtype = "html"
50+
_thread.start_new_thread(self.send_comment_email, (msg))
4651

47-
result = msg.send()
4852
if self.parent_comment:
4953
html_content = """
5054
您在 <a href="%s" rel="bookmark">%s</a> 的评论 <br/> %s <br/> 收到回复啦.快去看看吧
@@ -55,7 +59,7 @@ def save(self, *args, **kwargs):
5559
tomail = self.parent_comment.author.email
5660
msg = EmailMultiAlternatives(subject, html_content, from_email='no-reply@lylinux.net', to=[tomail])
5761
msg.content_subtype = "html"
58-
result = msg.send()
62+
_thread.start_new_thread(self.send_comment_email, (msg))
5963

6064
def __str__(self):
6165
return self.body

0 commit comments

Comments
 (0)