Hello everyone, I am the blogger of csdn: lqj_ myself
This is my personal blog homepage:
lqj_I_Python artificial intelligence vision (opencv) from entry to actual combat, front end, WeChat applet-CSDN blog The
latest uniapp graduation design column is also placed below:https://blog.csdn.net/lbcyllqj/category_12346639.html?spm=1001.2014.3001.5482
Usually, I will also explain some things that you usually use in the Bilibili video,
Welcome to Bilibili:
Lu Miaoer's personal space-Lu Miaoer's personal homepage-哔哩哔哩Video
Table of contents
First import the library used in this program
Create user interaction and let them enter their email account and password
Call the poplib library to use the POP3 protocol
Automatically obtain the latest information data
Create an array and store the decoded mail data into the array
Create a function def checkEmailSubject(), and detect the subject of the email
written in front
The function implemented in this blog is based on python to automatically send and receive emails, so as to realize the function of mobile phone remote control computer.
Here I refer to the control function of [Sunflower Control Software], and combine python and pOp3 protocol to judge the email information sent from the mobile terminal according to the keywords I set, so as to complete the remote control of the PC terminal.
code analysis
First import the library used in this program
import os
import time
import poplib
import email
from email.header import decode_header
Create user interaction and let them enter their email account and password
name = input('请输入你的163网易邮箱用户名(或手机号):')# 读取Email,获取Email主题
password = input('请输入你的163网易客户端授权密码:')
create function
def getEmailSubject():
Call the poplib library to use the POP3 protocol
read = poplib.POP3('pop.163.com')
read username and password
read.user(name)# 163邮箱用户名
read.pass_(password) # 163邮箱设置中的客户端授权密码
read mail message
allEmails = read.stat() # 读取邮件信息
Automatically obtain the latest information data
topEmail = read.top(allEmails[0], 0) # 获取最新的一封邮件
Create an array and store the decoded mail data into the array
tmp = []
# 解码邮件,存入tmp
for s in topEmail[1]:
try:
tmp.append(s.decode())
except:
try:
tmp.append(s.decode('gbk'))
except:
tmp.append(s.decode('big5'))
message = email.message_from_string('\n'.join(tmp))
Get email subject
subject = decode_header(message['Subject'])
if subject[0][1]:
subjectDecode = subject[0][0].decode(subject[0][1])
else:
subjectDecode = subject[0][0]
return subjectDecode
Create a function def checkEmailSubject(), and detect the subject of the email
while True:
subject = getEmailSubject()
print('代码运行中........')
print('代码正在运行中,请勿关闭!' + subject)
Set judgment conditions
if subject == '重启':
os.system('shutdown -r -t 3')
break
if subject == '关机':
os.system('shutdown -s -t 3')
break
Set detection time
time.sleep(60) #每1分钟自动检测一次
last execution
if __name__ == '__main__':
checkEmailSubject()
All code provided
import os
import time
import poplib
import email
from email.header import decode_header
name = input('请输入你的163网易邮箱用户名(或手机号):')# 读取Email,获取Email主题
password = input('请输入你的163网易客户端授权密码:')
def getEmailSubject():
read = poplib.POP3('pop.163.com')
read.user(name)# 163邮箱用户名
read.pass_(password) # 163邮箱设置中的客户端授权密码
allEmails = read.stat() # 读取邮件信息
topEmail = read.top(allEmails[0], 0) # 获取最新的一封邮件
tmp = []
# 解码邮件,存入tmp
for s in topEmail[1]:
try:
tmp.append(s.decode())
except:
try:
tmp.append(s.decode('gbk'))
except:
tmp.append(s.decode('big5'))
message = email.message_from_string('\n'.join(tmp))
# 获取邮件主题
subject = decode_header(message['Subject'])
if subject[0][1]:
subjectDecode = subject[0][0].decode(subject[0][1])
else:
subjectDecode = subject[0][0]
return subjectDecode
def checkEmailSubject():# 检查Email的主题
while True:
subject = getEmailSubject()
print('代码运行中........')
print('代码正在运行中,请勿关闭!' + subject)
if subject == '重启':
os.system('shutdown -r -t 3')
break
if subject == '关机':
os.system('shutdown -s -t 3')
break
time.sleep(60) #每1分钟自动检测一次
if __name__ == '__main__':
checkEmailSubject()