首页 > IT职业 > IT生活 > python邮件发送开服记录
#-*-coding:utf-8 -*-
#!/usr/bin/python
import sys
reload(sys) # reload 才能调用 setdefaultencoding 方法
sys.setdefaultencoding('utf-8') # 设置 'utf-8'
import MySQLdb
import houtai_dbname
from email.mime.text import MIMEText
from email.header import Header
import smtplib
#第三方服务smtp
mail_host='smtp.yeah.net'
mail_user='xxxx'
mail_pass='xxxx'
mail_postfix= 'yeah.net'
receivers='xxx@sina.com'
def get_addserver():
number=" "
global conn,plname
defdb=houtai_dbname.check_plname(plname)
try:
cur = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
conn.select_db(defdb) #选择数据库
sql= "SELECT count(*) as num,state from serverinfo where pf='%s' and zoneid" #邮件发送方
message = MIMEText(content, 'plain', 'utf-8') #邮件内容
message['subject'] = subject #邮件标题
message['from'] = me #发送方
message['to'] = receivers #接收方
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host) #连接smtp
smtpObj.login(mail_user,mail_pass) #登录
smtpObj.sendmail(me,receivers, message.as_string()) #获取参数发送邮件
smtpObj.close() #关闭
print "邮件发送成功"
except Exception,e:
print "ERROR,无法发送邮件"
print e
if __name__=="__main__":
id=" "
dic=houtai_dbname.houtaidic
for i in dic:
#print i,dic[i]
plname= i
conn=MySQLdb.connect(host="%s" % dic[i],user='xxxx',passwd='xxx',port=3306,charset='utf8')
max_server=get_addserver()
id=id+max_server
#print id
send_mail('xxx@sina.com','platfrom open servervices',id)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2260/viewspace-2802381/ ,如需转载,请注明出处,否则将追究法律责任。