阿里云邮箱发html邮件

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import datetime
import MySQLdb
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
#os.system('source /etc/profile')
import sys
import xlwt
import xlrd
import smtplib
from time import strftime, localtime
from datetime import timedelta, date
import calendar
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
#sys.path.append('/usr/lib64/python2.6/site-packages/cx_Oracle.so')

# 打开数据库连接
mydb = MySQLdb.connect("10.18.141.52","dba","xxxxxxx","ys" )

mycursor = mydb.cursor()
mycursor.execute('SET CHARACTER SET utf8;')
mycursor.execute('SET NAMES utf8;')
mycursor.execute('SET character_set_connection=utf8;')
sql2 = " CALL ys.pr_get_increament_report_by_plat_class1();"

try:
    mycursor.execute(sql2)
    results2 = mycursor.fetchall()
    mail_msg = results2[0][0]
#    print mail_msg
except Exception , e:
    print e

mycursor.close()
mydb.close()

#exit()
########################以下发送邮件############################

mail_host="smtp.mxhichina.com"  #设置服务器
mail_user="[email protected]"    #用户名
mail_pass="xxxxxxxxx"   #口令 
sender = '[email protected]'
receivers = ['[email protected]']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
message = MIMEText(mail_msg, 'html', 'utf-8')
message['From'] = Header("py增长监控", 'utf-8')
message['To'] =  Header("数据增长", 'utf-8')
subject = 'info数据增长'
message['Subject'] = Header(subject, 'utf-8')

try:
    smtpObj = smtplib.SMTP_SSL()
    smtpObj.connect(mail_host, 465)    # 25 为 SMTP 端口号
    smtpObj.login(mail_user,mail_pass)
    smtpObj.sendmail(sender, receivers, message.as_string())
    print "邮件发送成功   "
except smtplib.SMTPException,e:
    print e

你可能感兴趣的:(阿里云邮箱发html邮件)