如何在Django中调用exchange发送HTML邮件

发布网友 发布时间:2022-04-22 23:21

我来回答

2个回答

懂视网 时间:2022-05-10 13:22

为了以后使用方便,记录一下。

在工程settings.py首行添加内容"EMAIL_USE_TLS = True"

如何在Django中调用exchange发送HTML邮件

2.脚本内容

script file: usermail.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.core.mail import EmailMultiAlternatives,get_connection
from django.template.loader import render_to_string
from django.conf import settings 
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
 
def userMail(tousers,obj,html_content):
 conn = get_connection()
 conn.username = 'ops'
 conn.password = '123456'
 conn.host = 'exchange.test.com'
 try:
 conn.open()
 EMAIL_HOST_USER = 'ops@test.com'
 subject, from_email, to = obj, EMAIL_HOST_USER, tousers
 msg = EmailMultiAlternatives(subject, html_content, from_email, to)
 msg.attach_alternative(html_content, "text/html")
 conn.send_messages([msg,])
 conn.close()
 except Exception,e:
 print e

热心网友 时间:2022-05-10 10:30

SQL Server貌似不能发邮件,需要发邮件的话,建立采用其它的编程方式

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com