码迷,mamicode.com
首页 > Web开发 > 详细

Django发HTML邮件

时间:2018-12-20 17:01:20      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:settings   except   主题   nbsp   template   hello   email   default   com   

1.settings配置

1 EMAIL_HOST = XXXX
2 DEFAULT_FROM_EMAIL = 张宁 <zhang.ning@XXX.com>
3 RECEIVER =[zhang.ning@XXX.com]
4 CCER=[zhang.ning@XXX.com,]

2.views

 1 from django.shortcuts import render, HttpResponse
 2 from django.template import loader#*****
 3 from django.core.mail import EmailMultiAlternatives #***
 4 from django.conf import settings#****
 5 #只要定义好主题和内容即可,其他的在配置文件使用
 6 # Create your views here.
 7 def index(request):
 8     try:
 9         subject = hello
10         html_content = loader.render_to_string(tb.html)
11         msg = EmailMultiAlternatives(subject, html_content, settings.DEFAULT_FROM_EMAIL, settings.RECEIVER,settings.CCER)
12         msg.content_subtype = "html"
13         msg.send()
14     except Exception as e:
15         return HttpResponse("NO")
16     return HttpResponse("ok")

 

Django发HTML邮件

标签:settings   except   主题   nbsp   template   hello   email   default   com   

原文地址:https://www.cnblogs.com/yspass/p/10149879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!