Two days ago saw an article, using Python to implement e-mail control of the computer's interesting small program
Python video tutorial for controlling the Python version of the computer
But I had no contact with Python and then I thought I could use Java, so I wrote a Java version of
Initially want to connect the mail server with the socket, but more trouble, so found an easy-to-use method, using JavaMail
First, learn to use JavaMail
First we have to implement the use of Java to send and receive mail functions, through the data, we need to learn javamail,javamail development needs to use the following two jar package
: Dot Me
Import the above two jar package into the javaproject can happily use Java to send and receive e-mail, this tutorial a lot of online, there are many videos, I attach two bar:
Java Send mail JavaMail API Core class
Second, realize the idea: ( we use IMAP protocol )
1. Connect to the mail server, we must go through all the mail, find the one we are looking for, is to find new mail from the specified mailbox
2. Locate the specified message, get the subject of the message assigned to the variable, and then set the message to read
3. Call Java to control the functions of the Windows system and then pass in the subject control command.
Problems encountered:
1. How can I get new mail at any time? So we thought of multi-threading, so I used a thread-dead loop to iterate through the mailing list, with the specified new mail immediately accepted (but there are still some problems in the process Control)
2, sometimes connect the mail server will time out, but continue to wait and will connect (temporarily unresolved)
Third, the Code test: (Sina mailbox as an example)
First we need to determine some of the Sina mailbox configuration
Test procedure:
Run may report a connection to the server exception
Because it executes in multiple threads, it will reconnect to the server itself.
Example of success: sending a message with the subject Notepad will open Notepad, such as
Because of beginners javamail and multithreading, this program is not perfect, and continue to improve learning in the future, I think their python version of the very dick, but also to learn, take time to see the Python version of the implementation principle
Program source code Download:
Do me a little harder!
Executable Jar Package:
Hang Me up!
Executable Jar Package Run method:
A Java environment can double-click Open (Compile version jdk1.8.20)
If you look at the printing information of the program, you can put the jar package on the desktop:
can also be run.
How to use e-mail to control your PC with Java implementation