码迷,mamicode.com
首页 > 编程语言 > 详细

python邮件发送开服记录

时间:2018-01-22 19:31:35      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:open   postfix   head   rgs   smt   net   out   lib   set   

#-*-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)

python邮件发送开服记录

标签:open   postfix   head   rgs   smt   net   out   lib   set   

原文地址:http://blog.51cto.com/yzg784534398/2063785

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!