轉載於: 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, [收件人列表]):