版权声明:禁止转载至其它平台,转载至博客需带上此文链接。 https://blog.csdn.net/qq_41841569/article/details/85029664
前边发了Python利用smtplib库发送邮件,现在我们来应用一下那部分知识,制作一个利用邮箱远程控制电脑的软件,该软件一共分为两部分,一部分为控制端,另一部分为被控端。先看一下界面:
学习Python中有不明白推荐加入交流群
号:960410445
群里有志同道合的小伙伴,互帮互助,
群里有不错的视频学习教程和PDF!
如果有看过小编发表有关生日计时的文章,应该很容易搭建出这个简单的界面;功能呢,主要是控制端给指定邮箱发送邮件,然后被控制端读取邮箱内的邮件,解析其内容,并根据内容控制电脑(比如:关机,播放音乐、电影之类的,可以根据自己的需求自行加入功能)。
废话不多说,直接上干货:
#! /usr/bin/env python #coding=utf-8 from Tkinter import* import smtplib from email.mime.text import MIMEText from tkMessageBox import* def fa_song(biaoti): "fa song you jian,yi biao ti he nei rong wei can shu" _user="[email protected]" _pwd="XXXXXX" _to="[email protected]" string='人们都只看到,我长得很美丽,他们都不知道,我的心是善良的,都以为我很 坏,都以为我不实在,都以为我的心里没有一点爱,所以我变得很虚伪,到处在找机会, 谁要是爱上我,我就让谁倒霉' msg=MIMEText(string,"utf-8") msg["Subject"]=biaoti msg["From"]=_user msg["To"]=_to try: s=smtplib.SMTP_SSL("smtp.qq.com",465) s.login(_user,_pwd) s.sendmail(_user,_to,msg.as_string()) s.quit() print "Success!" showinfo(title="提示",message='发送成功!') except smtplib.SMTPException,e: showinfo(title='提示',message='发送失败!') print "Failied,%s"%e def Qchu(event): text11.delete('1.0','end') return def Chaxun(event): lujing=str(text11.get(1.0,'end')) lujing=lujing.strip() fa_song(lujing) def Guanji(event): lujing="off" fa_song(lujing) def wind(): win=Tk() win.minsize(220,120) win.maxsize(250,130) global text11,showinfo win.wm_title("玖郎") frame=LabelFrame(win,width=100,height=25,text="请输入发送内容") frame.pack() text11=Text(win,width=30,height=4) text11.tag_config('a',foreground='red') text11.pack() #按钮‘发送’ button=Button(win,text='发送',width=5,relief='sunken',height=1) button.bind('<Button-1>',Chaxun) button.pack(fill=X,expand=1,side=LEFT) #按钮‘关机’ button1=Button(win,width=5,height=1,text='关机',relief='sunken') button1.bind('<Button-1>',Guanji) button1.pack(fill=X,expand=1,side=RIGHT) #按钮‘清除’ button1=Button(win,width=5,height=1,text='清除',relief='sunken') button1.bind('<Button-1>',Qchu) button1.pack(fill=X,expand=1,side=RIGHT) win.mainloop() if __name__=="__main__": wind()
代码截图:
新手上路请多多关照,喜欢的朋友可以点下关注,每天都有更新!