发送邮件
- 首先登录你的邮箱开启smtp服务(以QQ邮箱为例)
登录–设置—账户—开启服务—拿到授权码 - settings.py 配置
EMAIL_HOST = 'smtp.qq.com'
EMAIL_HOST_USER = '12523@qq.com'
EMAIL_HOST_PASSWORD = 'xxxx'
- 建立路由,在视图里导入django内置的发送邮件类,发送邮件
from django.core.mail import send_mail, send_mass_mail
def mail_send(request):
m1 = ('邮箱主题', '1', '1251123@qq.com', ['1259123@qq.com'])
m2 = ('邮箱主题', '2', '1259123@qq.com', ['1259123@qq.com'])
m3 = ('邮箱主题', '3', '1279123@qq.com', ['1259123@qq.com'])
m4 = ('邮箱主题', '4', '1259123@qq.com', ['1251723@qq.com'])
send_mass_mail((m1, m2, m3, m4))
return HttpResponse('发送成功')
截图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3a15713e75e5ea81df1668949b2d97df.jpeg)