def send(request):# subject = "小伙子很帅"# message = "不禁夸啊"# send_mail(subject,message,"18332191389@163.com",["18332191389@163.com"])# return HttpResponse("ok")from django.core.mail import EmailMultiAlternativessubject, from_email, to = 'SUBJECT', '18332191389@163.com', '18332191389@163.com'text_content = 'This is an important message.'html_content = '' \'<p>This is an <strong>important</strong> message.</p>' \'<a href="https://blog.csdn.net/qq_41856814" >还是得看官网才行</a>' \''# msg = EmailMultiAlternatives(subject, text_content, from_email, [to])# msg.attach_alternative(html_content, "text/html")# msg.send()msg = EmailMessage(subject, html_content, from_email, [to])msg.content_subtype = "html" # Main content is now text/htmlmsg.send()return HttpResponse("ok")
settings.PY
EMAIL_HOST ="smtp.163.com"
EMAIL_PORT =465
EMAIL_HOST_USER ="18332191389@163.com"
EMAIL_HOST_PASSWORD ="XXXX"
EMAIL_USE_SSL =True
有问题找官网 别信csdn
https://docs.djangoproject.com/zh-hans/2.2/topics/email/