1、在 settings.py 的最后面加上类似这些
EMAIL_USE_SSL = True EMAIL_HOST = ‘smtp.qq.com‘ # 如果是 163 改成 smtp.163.com EMAIL_PORT = 465 EMAIL_HOST_USER = ‘[email protected]‘ # 帐号 EMAIL_HOST_PASSWORD = ‘[email protected]‘ # QQ邮箱的独立授权码 DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
2、新建一个测试文件sendmail.py
from django.core.mail import send_mail from .settings import DEFAULT_FROM_EMAIL email_title = "XXX" email_body = "XXX" email_to = "[email protected]" send_status = send_mail(email_title, email_body, DEFAULT_FROM_EMAIL, [email_to])
3.收工。
时间: 2024-10-11 04:00:33