1.settings配置
EMAIL_HOST = 'XXXX'
DEFAULT_FROM_EMAIL = '张宁 <zhang.ning@XXX.com>'
RECEIVER =['zhang.ning@XXX.com']
CCER=['zhang.ning@XXX.com',]
2.views
from django.shortcuts import render, HttpResponse
from django.template import loader#*****
from django.core.mail import EmailMultiAlternatives #***
from django.conf import settings#****
#只要定义好主题和内容即可,其他的在配置文件使用
# Create your views here.
def index(request):
try:
subject = 'hello'
html_content = loader.render_to_string('tb.html')
msg = EmailMultiAlternatives(subject, html_content, settings.DEFAULT_FROM_EMAIL, settings.RECEIVER,settings.CCER)
msg.content_subtype = "html"
msg.send()
except Exception as e:
return HttpResponse("NO")
return HttpResponse("ok")