import logging# zy: 评论邮件通知模块 - 处理评论相关的邮件发送功能 from django.utils.translation import gettext_lazy as _ from djangoblog.utils import get_current_site# zy: 导入项目工具函数,用于获取站点信息和发送邮件 from djangoblog.utils import send_email # zy: 创建日志记录器,用于记录邮件发送过程中的错误 logger = logging.getLogger(__name__) # zy: 发送评论邮件函数 - 处理评论发表和回复的邮件通知 def send_comment_email(comment): site = get_current_site().domain subject = _('Thanks for your comment') article_url = f"https://{site}{comment.article.get_absolute_url()}" html_content = _("""

Thank you very much for your comments on this site

You can visit %(article_title)s to review your comments, Thank you again!
If the link above cannot be opened, please copy this link to your browser. %(article_url)s""") % {'article_url': article_url, 'article_title': comment.article.title} tomail = comment.author.email send_email([tomail], subject, html_content) try: if comment.parent_comment: html_content = _("""Your comment on %(article_title)s
has received a reply.
%(comment_body)s
go check it out!
If the link above cannot be opened, please copy this link to your browser. %(article_url)s """) % {'article_url': article_url, 'article_title': comment.article.title, 'comment_body': comment.parent_comment.body} tomail = comment.parent_comment.author.email send_email([tomail], subject, html_content) except Exception as e: logger.error(e)