水痕 2019-12-05
setting.py
# 邮件配置 EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend‘ EMAIL_HOST = ‘smtp.exmail.qq.com‘ # 发送邮件的服务器地址 EMAIL_HOST_USER = ‘‘ # 不含‘@126.com’的后缀 EMAIL_HOST_PASSWORD = ‘‘ # 非邮箱登录密码 EMAIL_PORT = 25 EMAIL_USE_TLS = True EMAIL_FROM = ‘‘ # 设置默认的发件人,不设置的话,本例中不会出现问题,但是在实际django中实际运用时,会出现问题,参见 http://blog.chinaunix.net/uid-21142030-id-5768057.html
view.py
from django.core.mail import send_mail from dj_01 import settings def send(request): msg = ‘服务器运行良好‘ send_mail( subject=‘请注意这是Django邮件测试‘, message=msg, from_email=settings.EMAIL_HOST_USER, recipient_list=["",""], # 这里注意替换成自己的目的邮箱,不然就发到我的邮箱来了:) fail_silently = False, ) return HttpResponse(‘测试邮件已发出请注意查收‘)