python通過(guò)微信發(fā)送郵件實(shí)現(xiàn)電腦關(guān)機(jī)
Python 通過(guò)微信郵件實(shí)現(xiàn)電腦關(guān)機(jī),供大家參考,具體內(nèi)容如下
通過(guò)手機(jī)微信發(fā)送QQ郵件給sina郵箱,然后利用python的pop3定時(shí)檢查sina郵箱的郵件主題以及郵件來(lái)源,并在電腦執(zhí)行相應(yīng)的命令行實(shí)現(xiàn)關(guān)機(jī)。
Email_test【V1.0】
import poplib import os import time from email.parser import Parser from email.header import decode_header from email.utils import parseaddr #編碼轉(zhuǎn)換函數(shù) def decode_str(s): value, charset = decode_header(s)[0] if charset: value = value.decode(charset) return value #獲取email主題 def get_Subject(msg): #提取Subject信息 Subject = msg.get('Subject') #編碼轉(zhuǎn)換 Subject = decode_str(Subject) return Subject def judge(Subject, e_addr): if (Subject == '關(guān)機(jī)' and e_addr == '532101629@qq.com'): return 1 else: return 0 #檢索郵件主題 def Check_Subject(host, user, password): result = 0 try: pop_connect = poplib.POP3(host=host, timeout=3) print(pop_connect.getwelcome()) pop_connect.user(user) pop_connect.pass_(password) print('Messages: %s. Size: %s' % pop_connect.stat()) #服務(wù)器返回信息,消息列表,返回信息的大小。 number = len(pop_connect.list()[1]) print('消息列表長(zhǎng)度:', number) #檢索所有郵件 for index in range(1, number+1): #獲取第一封郵件信息 msglines = pop_connect.retr(index)[1] # 可以獲得整個(gè)郵件的原始文本(重新排版后的): str = b'\r\n' msg_content = str.join(msglines).decode('utf-8') print('\n', msg_content) #將原始郵件轉(zhuǎn)換為email實(shí)例: msg = Parser().parsestr(msg_content) # 獲取email主題 Subject = get_Subject(msg) print(Subject) # 獲取email地址 email_addr = parseaddr(msg.get('From'))[1] #信息判斷 result = judge(Subject, email_addr) print(result) #根據(jù)判斷結(jié)果,執(zhí)行操作 if result == 1: pop_connect.dele(index) break # 登出email pop_connect.quit() return result except Exception as e: print('login fail! ' + str(e)) quit() def main(): host = 'pop.sina.com' user = '********@sina.com' password = '********' while 1: result = Check_Subject(host, user, password) if result == 1: cmd = 'cmd /k shutdown -l' os.system(cmd) break time.sleep(60) # 兩次檢索郵件的時(shí)間間隔60s main()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python實(shí)現(xiàn)自動(dòng)發(fā)送郵件
- python3實(shí)現(xiàn)SMTP發(fā)送郵件詳細(xì)教程
- 使用python 3實(shí)現(xiàn)發(fā)送郵件功能
- python發(fā)送郵件腳本
- python發(fā)送郵件的實(shí)例代碼(支持html、圖片、附件)
- python中使用smtplib和email模塊發(fā)送郵件實(shí)例
- Python實(shí)現(xiàn)SMTP發(fā)送郵件詳細(xì)教程
- Python實(shí)現(xiàn)給qq郵箱發(fā)送郵件的方法
- python同時(shí)給兩個(gè)收件人發(fā)送郵件的方法
- python自動(dòng)發(fā)送郵件腳本
相關(guān)文章
用Python實(shí)現(xiàn)換行符轉(zhuǎn)換的腳本的教程
這篇文章主要介紹了用Python實(shí)現(xiàn)換行符轉(zhuǎn)換的腳本的教程,代碼非常簡(jiǎn)單,包括一個(gè)對(duì)操作說(shuō)明的功能的實(shí)現(xiàn),需要的朋友可以參考下2015-04-04Python實(shí)現(xiàn)給文件添加內(nèi)容及得到文件信息的方法
這篇文章主要介紹了Python實(shí)現(xiàn)給文件添加內(nèi)容及得到文件信息的方法,可實(shí)現(xiàn)從文件開(kāi)頭添加內(nèi)容的功能,需要的朋友可以參考下2015-05-05mac系統(tǒng)下安裝pycharm、永久激活、中文漢化詳細(xì)教程
這篇文章主要介紹了mac系統(tǒng)下安裝pycharm、永久激活、中文漢化詳細(xì)教程,需要的朋友可以參考下2020-11-11python 讀取文件并把矩陣轉(zhuǎn)成numpy的兩種方法
今天小編就為大家分享一篇python 讀取文件并把矩陣轉(zhuǎn)成numpy的兩種方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-02-02python各層級(jí)目錄下import方法代碼實(shí)例
這篇文章主要介紹了python各層級(jí)目錄下import方法代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01Python摳圖教程之使用OpenCV實(shí)現(xiàn)背景去除
這篇文章主要給大家介紹了關(guān)于Python摳圖教程之使用OpenCV實(shí)現(xiàn)背景去除的相關(guān)資料,背景去除是在很多視覺(jué)應(yīng)用里的主要預(yù)處理步驟,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-10-10