编写一个程序,每15分钟检查电子邮件账户
获取用电子邮件发送的所有指令,并自动执行这些指令
获取内容,打开对应的程序
#! python3
# 通过电子邮件控制你的电脑.py
# 编写一个程序,每15分钟检查电子邮件账户
# 获取用电子邮件发送的所有指令,并自动执行这些指令
# 获取内容,打开对应的程序
import subprocess,smtplib,imapclient,pyzmail,time,datetime
# 基本参数
minutes15 = datetime.timedelta(seconds=3)
fromMail = ''
secretCode = ''
softwareDict = {
'计算器':'calc.exe',
'画图':'mspaint.exe',
'记事本':'notepad.exe',
'截图':'SnippingTool.exe'
}
while True:
# 邮件设置
print('开始链接...')
imapObj = imapclient.IMAPClient('imap.qq.com', ssl=True)
imapObj.login(fromMail, secretCode)
print('链接成功...')
# 搜索最新文件标题(指令)
print('开始搜索收件箱...')
imapObj.select_folder('INBOX')
UIDs = imapObj.search()
fetchObj = imapObj.fetch(UIDs,['BODY[]'])
lastUID = UIDs[-1]
pyzObj = pyzmail.PyzMessage.factory(fetchObj[lastUID][b'BODY[]'])
software = pyzObj.get_subject()
# 执行指令
if software in softwareDict:
print('接下来为您打开',software)
popenObj = subprocess.Popen("C:\\Windows\\System32\\"+softwareDict[software])
popenObj.wait() #等待执行完毕
else:
print('暂无收到任何指令')
# 收尾
imapObj.logout()
# 稍后启动
print('%d秒后将再次检测哦!\n\n'\
%(minutes15.seconds))
time.sleep(minutes15.total_seconds())