settings配置
EMAIL_HOST = 'smtp.qq.com' # 如果是163换成stmp.163.comEMAIL_PORT = 465 # qq邮箱的端口EMAIL_HOST_USER = '' # qq邮箱账号EMAIL_HOST_PASSWORD = '' # 密码不是qq邮箱密码,而是授权码DEFAULT_FROM_EMAIL = EMAIL_HOST_USEREMAIL_USE_SSL = True# 新浪的配置EMAIL_USE_TLS = FalseEMAIL_FROM = EMAIL_HOST_USE
views.py
# 发送邮件t = threading.Thread(target=send_mail, args=( f"您的文章{article_obj.title}新增了一条评论内容", content, settings.EMAIL_HOST_USER, [request.user.email],)) t.start()
最后在qq邮箱的设置 -> 账户里开启IMAP/SMTP,并取得授权码,赋值给EMAIL_HOST_PASSWORD