Use the POP3 protocol to manage your own mailbox
Email is a certificate of certification network identity, more importantly, to maintain the most important way to contact the network, and each netizen should keep your email address. But do you know how email work? what? not interested? ! - Suppose. . . Your email address is full, what do you plan? . . ? Interested is not. If you know that there is a protocol called POP3, you can easily manage your own mailbox, you don't have to look at the full box of garbage, you don't have to look at Outlook slow "is charged the 185th letter, there are 308 "And distressed the numbers on the bill.
In the university, let's first understand the principle of email. There are two basic protocols on emails. One must be understood: One is SMTP (Simple Mail Transfer Protocol, Simple Mail Transfer Protocol), it is responsible for sending your friends to a friend's mailbox via the Internet, here we do not discuss Another agreement is POP3 (Post Office Protocol version 3, post office protocol version 3), from literally, we can see that the protocol is to help you get a letter stored in your mailbox. Through these two basic email agreements, we have implemented this email system. Of course, additional protocols can also achieve exchange of electronic letters, but basic protocols are both, and any email system must implement them. The basic content of the POP3 protocol is: 1. First of all, customers (generally a similar Outlook software) created a connection with the email server over the network (the bookmark socket). After completing, both sides can call each other and "eyebrows".
2. The customer sends its own username, which is your own mailbox @, the name of the previous system (some system requires the full name, you need to bring together with the domain name of @.
3. The customer waits for the server's response. If the server is checked, it is considered that it is a legitimate user, which will give you a reply of " ok". It can be followed.
4. The customer sends the user's password.
5. After passing, the server sends a OK "response. Now enter the status after identification, you can send some commands to the server. Generally supported basic commands:
The STAT Request Server Sends a statistics on the mailbox, such as the total number of mailboxes, and the total number of bytes, no parameters need to bring the unique identifier for the mail with UIDL [MSG #], each identifier of the POP3 session will be unique, [ Msg #] is the parameters belled by this command, generally a string of a single (similar 36A5B1C608382) string. List [msg #] Returns the number of emails and the size of each message, if there is no parameters, it is to list all the mail size retr [msg #] returns all the text identified by the parameter, which allows the server to send your mailbox Some email full text. Under normal circumstances, these contents are not only available for the content of the mail client software, but a text string with standard gram-oriented control, which requires a special software to decode to see the specific content. The Dele [MSG #] server will mark the message marked by the parameter identity as delete, only one delete tag is made, and the message is not completely removed. The message is really deleted only after using the quit command. So, like Outlook Similar software will receive the last letter from the last time after the software is closed. The RSET server will reset all the messages marked as deleted, used to undo the DELE command TOP [MSG #] server will return to the front N row content before the parameter identifier, n must be a positive integer NOOP server to return a positive response, generally for Keep the connection with the server, the meaning is not big. 6. If everything goes (issued the command), you can use the quit command to disconnect the server connection. The command used is: quit. After receiving this command, the server will break the socket, then delete it. Make a message that deletes the tag. It can be seen that the server generally only issues two states: " OK" and " error". If an error occurs in the inspection phase, you must resume the inspection, and the error will be re-issued by verifying the error. After accepting " OK", the command just now gets the correct execution, which can be processed next or the next phase. The general server will give a textual state description of a piece of text in OK and " Error", explaining the execution of success or unsuccessful reasons.
In order to let everyone fully understand this principle, I write a VB applet, accept the command you entered, display the response returned by the server, so that everyone can fully feel the fresh stimulation of the server dialogue. Specific process: 1. Start VB, create a standard application engineering, join the Winsock control. This control is a tool we manipulated our computer with the mail server.
2. Set the control of the control to: 1 (TCP protocol), Remotehost is: pop.163.net (here I applied for a 163 user for testing, "pop.163.net" is the 163 post office dedicated to the user's credible POP3 The server, the user applied for: mytest2000, password: test2000, you can use this test, rest assured, I don't mind), RemotePort is: 110 (socket 110 of the POP3 protocol).
3. Add three Label controls, the CAPTION attribute is set to: "Server Response Content", "Reply:", "Send Command Area"; Add three TextBox, clear the text content. Where Text1 is used to display the response given by the server, Text2 records the contents of the two parties of this dialog process, and Text3 is used to output the command to the server. Add two command buttons for Command1 and Command2, Caption are "launch" and "send commands", respectively. 4. Write an event response code, as follows: private submmand1_click () text1.text = "now what" "" Displays the current state, no and server connection if winsock1.state = 7 Then 'If the socket connection, turn off Winsock1 .Close end ifwinsock1.connect 'Start connection Command1.Enabled = false' can no longer connect to End Sub
Private submed2_click () Winsock1.sendData text3.text 'Sends each command of the input to the server automatically clears text3.text = "" End Sub
Private sub winsock1_close () text1.text = "closed" End Sub
Private sub winsock1_connect () text1.text = "connection" End Sub
Private Sub Winsock1_DataArrival (Byval Bytestotal As Long) Dim Str AS Stringwinsock1.Getdata Str 'accepts data, displayed in Text1, add in Text2Text1.text = strText2.text = text2.text strend sub
Private submmand2_click () Winsock1.senddata text3.text 'Send the command text3.text = "" End Sub
This applet allows you to see the entire process of POP3, with it, you can also handle mailbox garbage. Everyone's test process can be like this (all quotes don't have to be entered, here is to indicate that the content should be entered, the mailbox is a real mailbox, everyone can test): 1. Click Command1 and wait for Text1 "Connected". 2. Then TEXT3 Enter: "User MyTest2000", " OK" information will enter the next step. 3. Enter "Pass Test2000" and wait for " OK" to indicate the identity confirmation. Otherwise, return to 2, re-enter the username. 4. At this point, you can use List, Stat, Dele, NOOP, UIDL, RSET, RETR, TOP, etc. At this point, the server is waiting for your command and manages your mailbox. Reference order series: StatListList 1Retr 1 ......
5. I hope to exit, enter "quit" and exit the conversation. Attach the work of my test procedure, you can see the content of my and pop.163.net ^ _ ^.
After learning the above POP3 process, we can design your own mail handler: For example, if the List is found that the data returned more than a certain amount can be determined as a malicious bomb, you can automatically issue the dele command to delete. Plus these logic you can automate your email. Of course, you can also use the deficiencies of the agreement itself to decipher the general person's password, but I don't want you to do this. If you have better suggestions and comments for using the POP3 protocol, please contact me by email (Yangshanhe@121cn.com) Yangshan River
==
2000 written