Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Python uses mail to remotely control its computers


Jun 01, 2021 Article blog



This article was reproduced to Know ID: Charles (Bai Lu) knows his personal column

Download the W3Cschool Mobile App, 0 Foundation Anytime, Anywhere Learning Programming >> Poke this to learn

Lead

Recently, it is often necessary to simply remotely control the computer, such as remote view of the computer model training, model training after remote shutdown of the computer and so on, so I want to use python to simply implement these functions, direct use of mail remote control of their own computer.

Let's get off to a pleasant start


Related documents

Web disk download link: https://pan.baidu.com/s/1yWiZPWKE44n1UxgkdFfMlQ

Password: 8jiq


Develop tools

Python version: 3.6.4

Related modules:

PIL module;

email module;

and some Python's own modules.


Environment construction

Install Python and add it to the environment variable, and pip installs the relevant modules that are required.


Introduction to the principle

Ideas

Every once in a while, the computer checks to see if a new message has been received in the specified mailbox, if not received, no action is taken, if it is received, the identity of the sender is determined, if the sender is the legitimate control, the sender's message is resolved, the results of the resolution are performed, otherwise the message is ignored.

Concrete implementation

(1) Send and receive mail

We use the POP3 protocol to collect mail, the SMTP protocol to send mail, python built-in support for both protocols, so the implementation is very simple and easy.

Note 1:

Here is recommended Liao Xuefeng's Python tutorial, which has a detailed description of sending and receiving mail, I will not move bricks.

Note 2:

Computer-side mailbox I used Sina mailbox, mobile phone mailbox I used QQ mailbox.

(2) Check the computer status

Take a screenshot of your computer directly using the ImageGrab.grab() function of the PIL module, and then send it to your phone via mail.

If you want to see how the model is running, just display the model training interface on the desktop before you go

(3) Scalability

In addition to checking the condition of your pc, you currently only support using the cmd command to control your PC, and if you need to add additional features, you can add them in the location shown in the following image:

 Python uses mail to remotely control its computers1

(4) Ease of use

Cmd command too long to fight on the phone is inconvenient or can not remember what to do? You can set up a shortcut command in word2cmd.json:

 Python uses mail to remotely control its computers2

(5)FAQ

(1) Failed to send mail on the computer side?

solution:

If the message sent by the computer side is recognized as spam so that the mobile phone side can not view the status of the computer, you can use the mobile phone to log into the computer side of the mailbox used to view the returned messages, so that you can view the computer health on the phone.

Note 3:

If you reject your phone's mailbox, you can set up a whitelist.

(2) Can't log in to the mailbox on the computer side?

solution:

You need to turn on SMTP and POP3 services:

 Python uses mail to remotely control its computers3  Python uses mail to remotely control its computers4

The password should be the client authorization password, not the login password. Of course, Sina mailbox login password is the client authorization password.

That's All.

Please refer to the relevant documents for the full source code.

Use the demo

Step1: Modify the profile

The profiles that must be modified are:

config.json。

function:

Set up information for your computer and phone's mailbox. The information of the mobile mailbox is used to verify that the sender is the person who controls the computer legally, and the information of the computer mailbox is used to receive and send mail on the computer side.

If you need to encrypt an SMTP session, set the enable_ssl to true and set the correct port number.

 Python uses mail to remotely control its computers5

The profile you choose to modify is:

word2cmd.json。

function:

Set up a shortcut command language.

Step2: Run Server.py files

 Python uses mail to remotely control its computers6

Send instructions:

 Python uses mail to remotely control its computers7

 Python uses mail to remotely control its computers8

To execute instructions:

 Python uses mail to remotely control its computers9

outcome:

 Python uses mail to remotely control its computers10

That's All.


more

Code as of 2018-08-07 test is correct.

Packaged versions of exE files are available in the relevant files and can be used without configuration environment.