软件授权码Python之道--Python连接MYSQL数据库和发送邮件

文章结束给大家来个程序员笑话:[M]

    主机环境:Linux yan-Server 3.4.36-gentoo #3 SMP Mon Apr 1 14:09:12 CST 2013 x86_64 AMD Athlon(tm) X4 750K Quad Core Processor AuthenticAMD GNU/Linux

    Python版本:Python 2.7.4

    原创作品,转载请标明

    http://blog.csdn.net/yming0221/article/details/8965882

    

    Python 2还是选择Python 3?这是挺难抉择的。

    Python 2学习起来参考资料比较多,网上的开源的插件对Python 2支撑也比Python3好,容易学习。

    Python 3改进了Python 2的部份缺陷,详细我没有了解。原来想学习Python 3,mysql的Python 3插件一直没有搞定。

    虽然Python之父建议:如果你手里还有其他的Python项目,建议你学习Python 2,如果你是个初学者,建议直接学习Python 3。

    考虑到虽然版本更新,但是Python的思惟没变,我选择了Python 2。

    

    下面的程序的作用是给数据库注册的用户群发通知邮件,直接上代码

    每日一道理
时间好比一条小溪,它能招引我们奔向生活的海洋;时间如同一叶扁舟,它将帮助我们驶向理想的彼岸;时间犹如一支画笔,它会指点我们描绘人生的画卷。
#coding=utf-8
import MySQLdb

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import time

def send_email(receiver):

    smtpserver = 'smtp.qq.com'
    username = '***@qq.com'
    sender = '****@qq.com'
    password = '****'
    
    subject = 'GPS定位追踪-我的Ta你在哪'
    
    msg=MIMEMultipart('alternative')
    
    msg['Subject'] = subject
    msg['From'] = '****@qq.com'
    msg['To'] = receiver
    
    #邮件正文
    
    text="尊重的用户:\n您好,欢迎应用 GPS定位追踪--我的Ta你在哪 \n如果须要关注对方的位置,您须要让对方安装本软件登录账号,\
    \n根据Ta的帐号和Ta授权码(如何查看授权码?点击菜单键->设置\n->查看我的授权码便可) \
    \n您可以获得软件最新版本 下载地址 。\
    \n你也可以进入软件,点击设置->检查最新版本停止软件的升级。\
    \n该软件应用的是我们自己的服务器,可以放心应用。\
    \n如有任何问题请联系:\
    \n客服QQ:2294454734 \
    \n该邮件由系统自动收回,勿回复。"

    html="""
<div><font size="4"><span style="font-family: Simsun; line-height: normal;">
尊重的用户:</span><br style="font-family: Simsun; line-height: normal;">
<span style="font-family: Simsun; line-height: normal;">    您好,欢迎应用<font color="#ff0000"> 
<b>GPS定位追踪--我的Ta你在哪 </b></font></span></font></div><div><font size="4">
<span style="font-family: Simsun; line-height: normal;">如果须要关注对方的位置,您</span>
<span style="font-family: Simsun; line-height: normal;">须要让对方安装本软件登录账号,</span>
</font></div><div><font size="4">
<span style="font-family: Simsun; line-height: normal;">根据<font color="#ff0000">
<b>Ta的帐号和Ta授权码</b></font></span></font>
<span style="font-size: large; font-family: Simsun; line-height: normal;">(如何查看授权码?</span>
<span style="font-size: large; font-family: Simsun; line-height: normal;">点击菜单键->设置</span></div><div>
<span style="font-size: large; font-family: Simsun; line-height: normal;">->查看我的授权码便可)</span></div>
<div><font size="4"><b><span style="font-family: Simsun; line-height: normal;"><br></span></b></font></div>
<div><font size="4"><b><span style="font-family: Simsun; line-height: normal;">您可以获得软件最新版本 </span>
<a href="http://121.199.5.19/download/TouchYou.apk" style="font-family: Simsun; line-height: normal;">下载地址</a>
<span style="font-family: Simsun; line-height: normal;"> 。</span></b></font></div><div>
<span style="font-family: Simsun; line-height: normal; font-size: large;">你也可以进入软件,点击<font color="#ff0000">
<b>设置->检查最新版本</b></font>停止软件的升级。</span></div><div><font size="4">
<span style="font-family: Simsun; line-height: normal;">该软件应用的是我们自己的服务器,可以放心应用。</span></font>
</div><div><font size="4"><span style="font-family: Simsun; line-height: normal;"><br></span></font></div><div>
<font face="Simsun" size="4"><span style="line-height: normal;">如有任何问题请联系:</span></font></div><div>
<font face="Simsun" size="4" color="#ff0000"><span style="line-height: normal;"><b>客服QQ:2294454734</b>
</span></font><br>该邮件由系统自动收回,勿回复。
</div>
    """
    part1=MIMEText(text,'plain',_charset='utf-8')
    part2=MIMEText(html,'html',_charset='utf-8')
     
    msg.attach(part1)
    msg.attach(part2)
    
    
    #开始发送
    smtp = smtplib.SMTP()
    smtp.connect(smtpserver)
    smtp.login(username, password)
    try:
        smtp.sendmail(sender, receiver, msg.as_string())
        time.sleep(60)#等待一分钟,避免被服务器屏蔽
    except:
        print receiver
        print(' 邮件发送失败!')
        
    smtp.quit()
    print(receiver)
    print(' 邮件发送成功!')


#连接
cxn = MySQLdb.Connect(host = 'localhost', user = 'root', passwd = '**')

#游标
cur = cxn.cursor()


#创立数据库

cur.execute("USE login")


#查询
print cur.execute("SELECT email FROM user  order by id desc")
for row in cur.fetchall():
    for mail in row:
        #send_email(mail)
        print mail

#关闭
cur.close()
cxn.commit()
cxn.close()

    也趁便说一下,本人做的一个Android的GPS定位追踪软件,大家有兴趣的可以安装体验一下。下载地址:

    http://121.199.5.19/download/TouchYou.apk

文章结束给大家分享下程序员的一些笑话语录:  一边用着越狱的ip,一边拜乔帮主的果粉自以为是果粉,其实在乔帮主的眼里是不折不扣的叛徒。

--------------------------------- 原创文章 By 软件和授权码 ---------------------------------

posted @ 2013-05-23 19:45  xinyuyuanm  阅读(486)  评论(0编辑  收藏  举报