#-*-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<8000 GROUP BY state order by state" % (plname) cur.execute(sql) #执行sql result=cur.fetchall() #获取的数据集结 cur.close() #关闭游标 conn.close() #关闭数据库 except MySQLdb.Error,e: #print "MySQLdb error %d:%s " % (e.args[0],e.args[1]) print e print result for i in result: number=plname+","+number+str(i['num'])+"," #stri="当前该平台已开区 %s" % (result['num']) print number return number def send_mail(mail_to,subject,content): me = mail_user+"<"+mail_user+"@"+mail_postfix+">" #邮件发送方 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)
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦