其中:
yagmail.register(username, password)会使用到keyring模块,安装如下:
pip install keyring后面我们可以根据自己的需求编写一些其它功能 。下面是完整的代码:
import osimport timeimport yagmailfrom imbox import Imboxfrom PIL import ImageGrabdef send_mail(sender, to, contents): smtp = yagmail.SMTP(user=sender, host='smtp.163.com') smtp.send(to, subject='Remote Control', contents=contents)def read_mail(username, password): with Imbox('imap.163.com', username, password, ssl=True) as box: all_msg = box.messages(unread=True) for uid, message in all_msg: # 如果是手机端发来的远程控制邮件 if message.subject == 'Remote Control': # 标记为已读 box.mark_seen(uid) return message.body['plain'][0]def shutdown(): os.system('shutdown -s -t 0')def grab(sender, to): surface = ImageGrab.grab() surface.save('surface.jpg') send_mail(sender, to, ['surface.jpg'])def main(): username = 'sockwz@163.com' password = '你的授权码' receiver = '2930777518@qq.com' time_space = 5 yagmail.register(username, password) while True: # 读取未读邮件 msg = read_mail(username, password) if msg: if msg == 'shutdown': shutdown() elif msg == 'grab': grab(username, receiver) time.sleep(time_space)if __name__ == '__main__': main()
【Python实现用手机监控远程控制电脑】
推荐阅读
- 增程汽车|国内首款全尺寸豪华增程SUV!理想L9银色实车曝光:不同光线会“变色”
- 真实向日葵蓝天阳光图片,好看的向日葵花束图片大全
- 和面|丝芙兰连锁推荐 实惠又好用的护肤品套装排行榜 用一次就无限回购
- 如何评价廖化,廖化活了多大
- 动感单车有什么作用呢
- 菩提树种子图片,菩提树果实图片
- 什么是敏捷开发,敏捷开发实行中各岗位职能是什么?
- Pythonic风格代码有什么好处?附12个代码实例
- C++实现线程池
- 真实的慈安太后怎么死的,慈安为什么能当皇后
