Django 發送html郵件


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM