#coding: Utf-8#python 2.7.10#author conardimport poplib,emailfrom email.header Import Decode_headerimport Smtplibimport timeimport os,syshost = "pop3.163.com" username = "[email protected]" #slavemailpassword = "xxxx" def A Ccp_mail (): flag=1 pp = poplib. POP3 (Host) Pp.set_debuglevel (1) pp.user (username) pp.pass_ (password) ret = Pp.stat () ret = pp.list () Dow n = pp.retr (len (ret[1))) Mn=down[1][14].decode (' utf-8 ') #host Mail ms=down[1][13].decode (' utf-8 ') #subject if (Mn==u ' From:hostmail_name ') and (Ms==u ' Subject:shutdown '): Flag = 0 pp.quit () return flagdef upda_mail (): Handle = Smtplib. SMTP (' smtp.163.com ', +) Handle.login (username,password) msg = "To:slavemail_name\r\nfrom:slavemail_name\r\nsubjec T:waiting \r\n\r\nnull \ r \ n "handle.sendmail (' slavemail_name ', ' slavemail_name ', msg) handle.close () Def resp_mail (): Handle = Smtplib. SMTP (' smtp.163.com ', +) Handle.login (username,password) msg = "To:hostmail_name\r\nfrom:slavemail_name\r\nsubject:shutdown completed\r\n\r\ndone\r\n "Handle.sendmail (' Slavemail_name ', ' hostmail_name ', msg) handle.close () if __name__== ' __main__ ': While 1:time.sleep (5) If Accp_mail () ==0:upda_mail () #让slave邮箱给自己发一封主题不同于shutdown的邮件 resp_mail () #让slave邮箱给host邮箱 Send Feedback Os.system (' regedit ') #os. System (' Shutdown-s-t 300-c closing ... ') #关机, the shutdown command can be canceled within 300s Break
Replace Slavemail_name with the name of the mailbox, such as [email protected],hostmail_name replace the primary mailbox name
Reference:
http://www.zhihu.com/question/27065450
Https://github.com/kingname/MCC
Control of remote PC by sending mail