用django实现邮件发送
settings配置
EMAIL_HOST = 'smtp.qq.com' # 如果是163换成stmp.163.com EMAIL_PORT = 465 # qq邮箱的端口 EMAIL_HOST_USER = '' # qq邮箱账号 EMAIL_HOST_PASSWORD = '' # 密码不是qq邮箱密码,而是授权码 DEFAULT_FROM_EMAIL = EMAIL_HOST_USER EMAIL_USE_SSL = True # 新浪的配置 EMAIL_USE_TLS = False EMAIL_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