settings的配置
# smtp服务的邮箱服务器
EMAIL_HOST = 'smtp.163.com'
# smtp服务固定的端口是25
EMAIL_PORT = 25
# 发送邮件的邮箱
EMAIL_HOST_USER = 'XXX@163.com'
# 在邮箱中设置的客户端授权密码
EMAIL_HOST_PASSWORD = 'INKCXEUXHBFVELTK'
# 收件人看到的发件人 <此处要和发送邮件的邮箱相同>
EMAIL_FROM = 'python<XXX@163.com>'
def mail_send(request):
# 发送一封邮件
# res = send_mail('发送邮件','发送了一封邮件',EMAIL_FROM,['landmark_csl@126.com','y1570069809@163.com'])
# 发送多封邮件
# message1 = ('1', '<b>发送1邮件</b>', EMAIL_FROM, ['landmark_csl@126.com','y1570069809@163.com'])
# message2 = ('2', '<b>发送2邮件</b>', EMAIL_FROM, ['landmark_csl@126.com','y1570069809@163.com'])
# send_mass_mail((message1, message2), fail_silently=False)
# html格式邮件
html_content = loader.get_template('active.html').render({'username': 'ZZ'})
msg = EmailMultiAlternatives('html', from_email=EMAIL_FROM, to=['XXX@163.com'])
msg.attach_alternative(html_content, "text/html")
msg.send()
return HttpResponse("邮件发送")