转载于: http://blog.sina.com.cn/s/blog_76e94d2101011bxd.html
django中发送html邮件:
#mailer.py
# -*- coding: utf-8 -*-
from django.core.mail import EmailMessage
from django.template import loader
from settings import EMAIL_HOST_USER #项目配置邮件地址,请参考发送普通邮件部分
def send_html_mail(subject, html_content, recipient_list):
msg = EmailMessage(subject, html_content, EMAIL_HOST_USER, recipient_list)
msg.content_subtype = "html" # Main content is now text/html
msg.send()
subject = u'邮件主题'
html_content = loader.render_to_string(
template_path, #需要渲染的html模板
{
‘paramters’:paramters #参数
}
)
send_html_mail(subject, html_content, [收件人列表]):