Django使用n内置模块发送HTML格式的邮件
生活随笔
收集整理的這篇文章主要介紹了
Django使用n内置模块发送HTML格式的邮件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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" >還是得看官網(wǎng)才行</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有問題找官網(wǎng) 別信csdn
https://docs.djangoproject.com/zh-hans/2.2/topics/email/
總結(jié)
以上是生活随笔為你收集整理的Django使用n内置模块发送HTML格式的邮件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FishC笔记—18 讲 函数:灵活即强
- 下一篇: 2017年html5行业报告,云适配发布