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=‘[email protected]‘

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(‘[email protected]‘,‘platfrom open servervices‘,id)

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

时间: 2024-09-29 16:36:16

python邮件发送开服记录的相关文章

python邮件发送

在基于互联网的应用中,程序经常需要自动地发送电子邮件.如:一个网站的注册系统会在用户注册时发送一封邮件来确认注册:当用户忘记登陆密码的时候,通过邮件来取回密码.smtplib模块是python中smtp(简单邮件传输协议)的客户端实现.我们可以使用smtplib模块,轻松的发送电子邮件.下面的例子用了不到十行代码来发送电子邮件: #coding=gbk import smtplib smtp = smtplib.SMTP() smtp.connect("smtp.yeah.net", 

linux下mutt邮件发送系统安装操作记录

之前介绍了Linux下sendmail和sendemail邮件系统环境部署,今天介绍下使用mutt发送邮件的环境部署过程.mutt这个软件,它是一款基于文字界面的邮件客户端,是一款功能强大的email程序,非常小巧,可以用它来读写,回复保存和删除你的邮件,能在linux命令行模式下收发邮件和附件. 1)mutt的安装[[email protected] ~]# yum -y install sendmail                  //需要安装sendmail并开启防火墙的25端口,如

python 邮件发送

#!/usr/bin/env python # -*- coding:UTF-8 -*- #需要在邮箱处设置开启SMTP服务(第三方客户端发送) import smtplibfrom email.mime.text import MIMETextfrom email.utils import formataddrdef mail(): ret = True try: msg = MIMEText('测试邮件','plain','utf-8') msg['From'] = formataddr([

Python邮件发送脚本(Linux,Windows)通用

脚本 #!/usr/bin/python #-*- coding:utf-8 -*- #Python Mail for chenglee #if fileformat=dos, update fileformat=unix #code:set fileformat=unix #check:set ff ? import smtplib from email.mime.text import MIMEText from email.utils import formataddr my_sender

Python开发游戏开服脚本

#!/usr/bin/env python #coding:utf-8 from pymongo import MongoClient import datetime import random import shutil import time import sys import re import os class readyTostart(object): def Countdown(self): print(''' ####################################

Python邮件发送源码

从最初的实现邮件发送功能,改了几次,有了如下代码. 该代码还可以继续开发,完善.以实现更复杂的功能. #-*- coding:utf-8 -*- i = 0 while i < 10: import smtplib from email.mime.text import MIMEText from email.header import Header import time # 第三方 SMTP 服务 mail_host="smtp.qq.com" #设置服务器 mail_use

python邮件发送脚本

转自:http://phinecos.cnblogs.com/ 1 #!/usr/bin/python 2 #coding=utf-8 3 4 #@author:dengyike 5 #@date:2010-09-28 6 #@version:1.0 7 #@description: auto sending email with attachment file 8 9 import email 10 import mimetypes 11 from email.MIMEMultipart im

python 邮件发送的代码 网上的方法汇总一下

一.文件形式的邮件 #!/usr/bin/env python3#coding: utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Header sender = '***'receiver = '***'subject = 'python email test'smtpserver = 'smtp.163.com'username = '***'password = '***' msg

python 邮件发送 zabbix 图片

获取图片 http://www.iyunv.com/thread-21332-1-1.html 邮件内嵌图片 http://www.tuicool.com/articles/vaAVri