您现在的位置是: 网站首页> 学习笔记> Django Django

django使用qq邮箱发送邮件

2021-01-02 [邮件] 4372人已围观

settings.py中添加如下设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_SSL = True    # 这个一定要设置,不然会报smtplib.SMTPServerDisconnected:Connection unexpectedly closed异常
EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = '465'
EMAIL_HOST_USER = 'xxx@qq.com'
EMAIL_HOST_PASSWORD = 'xxxqbnnffoubijj'   # 这个密码是在qq邮箱中开启smtp功能时邮qq邮箱生成的,直接拷过来用
EMAIL_FROM = '此处起个好听的名字<xxx@qq.com>'

在view中发送邮件:

from django.conf import settings
from django.core.mail import send_mail

subject = '邮件主题'
message = '邮件正文'
sender = settings.EMAIL_FROM
receiver = ['xxx@qq.com', 'xxx@163.com']
send_mail(subject, message, sender, receiver)

文章评论

#2021-01-03 12:04 @ rrty:

简明

添加评论





本栏推荐

站点信息

  • 建站时间:2021-01-01
  • 网站程序:Django 3.1.2
  • 文章统计:53篇
  • 文章评论:35条
  • 统计数据