import logging from djangoblog.utils import get_current_site from djangoblog.utils import send_email logger = logging.getLogger(__name__) def send_comment_email(comment): site = get_current_site().domain subject = '感谢您发表的评论' article_url = "https://{site}{path}".format( site=site, path=comment.article.get_absolute_url()) html_content = """

非常感谢您在本站发表评论

您可以访问 %s 来查看您的评论, 再次感谢您!
如果上面链接无法打开,请将此链接复制至浏览器。 %s """ % (article_url, comment.article.title, article_url) tomail = comment.author.email send_email([tomail], subject, html_content) try: if comment.parent_comment: html_content = """ 您在 %s 的评论
%s
收到回复啦.快去看看吧
如果上面链接无法打开,请将此链接复制至浏览器。 %s """ % (article_url, comment.article.title, comment.parent_comment.body, article_url) tomail = comment.parent_comment.author.email send_email([tomail], subject, html_content) except Exception as e: logger.error(e)