利用程序来发邮件的作用挺多的,在脚本运行时发送一个邮件给你,然后你可以知道脚本运行了,做到一个实时的监控。
import smtplib
from email.header import Header
def sendtheback(str):
sendemaillsddress = "你的邮箱" #用于发送邮件的地址
sendemailpassword = "授权码" #邮箱的密码
sendemailhost = "smtp.qq.com" #邮箱的服务器地址
sendemailport = "465" #端口
recuveremailaddress = "接收的邮箱" #接收的邮箱
emailsubject = "关机"
emalicontent = str
message = MIMEText(emalicontent, 'plain', "utf-8")
message["From"] = Header(sendemaillsddress, "utf-8")
message["To"] = Header(recuveremailaddress, "utf-8")
emailclient = smtplib.SMTP_SSL(sendemailhost, sendemailport)
try:
emailclient.login(sendemaillsddress, sendemailpassword)
print("登录成功")
except:
print("登录失败")
else:
emailclient.sendmail(sendemaillsddress, recuveremailaddress, message.as_string())
print("发送完成")
finally:
emailclient.close()
主要程序很简单,登录然后发送内容,把传过来的str参数发送出去,然后记得把服务close掉就可以了
也可以利用摄像头拍摄一张照片,然后把截图发送出去
cap = cv2.VideoCapture(0)
cap.isOpened()
ret_flag, Vshow = cap.read()
pic_name = "example.png"
cv2.imwrite(pic_name, Vshow)
cap.release()
#中间要有你的邮箱和授权
message['Subject'] = subject
message['From'] = sender
message['To'] = receivers
content = MIMEText('<html><body><img src="cid:imageid" alt="imageid"></body></html>', 'html', 'utf-8')
message.attach(content)
jpgpart = MIMEApplication(open(pic_name, 'rb').read())
jpgpart.add_header('Content-Disposition', 'attachment', filename=pic_name)
message.attach(jpgpart)
try:
server = smtplib.SMTP_SSL("smtp.qq.com", 465)
server.login(sender, "授权码")
server.sendmail(sender, receivers, message.as_string())
server.quit()
print("发送成功")
except smtplib.SMTPException as e:
sendtheback("截图发送失败")
然后获取电脑桌面的截图:
content = MIMEText('<html><body><img src="cid:imageid" alt="imageid"></body></html>','html','utf-8')
message.attach(content)
img = ImageGrab.grab()
pic_name = time.strftime('%Y-%m-%d-%H-%M-%S')+'.jpg'
img.save(pic_name)
jpgpart = MIMEApplication(open(pic_name, 'rb').read())
jpgpart.add_header('Content-Disposition', 'attachment', filename=pic_name)
message.attach(jpgpart)
try:
server = smtplib.SMTP_SSL("smtp.qq.com",465)
server.login(sender,"授权码")
server.sendmail(sender, receivers, message.as_string())
server.quit()
print("发送成功")
except smtplib.SMTPException as e:
sendtheback("截图发送失败")
差不多就是这些简单的代码就可以实现利用上一篇的接收邮件,然后接收到邮件的内容,然后对内容判断,如果内容是要桌面截图,就调用桌面截图的代码,实现截图然后把截图发送出去。算是比较逼格的程序了。
人生苦短,我用python