G8341 (幄天)
http://www.codeproject.com/ There is a VB.NET instance download, but you want to modify it.
There is a document above, but it is English, SMTP: http://www.faqs.org/rfcs/rfc2554.html
Here are some simple POP3 data in Internet, POST Office Protocol 3) protocols are often used to receive emails. This agreement is easy to learn because it only contains 12 commands (three of which you can ignore their existence). These commands are used by the client computer to send to the remote server. Conversely, the server returns two response code to the client computer. If you haven't seen another article in this site - "Winsock Terminal Sample Program", please read the article first because you need that program to do experiments.
Run the sample program, click the "Connect to" button on the toolbar. Enter the address of the mail server you want to connect by entering the dialog box that pops up, for example:
Mail.comset.net
Select the POP3 protocol and click the "Connect" button. If successful (if an error, it must be a problem with your server address, don't doubt it on the program, you will see the information returned by the server in the text box. My server response is as follows:
OK POP3 mail.comset.net v5.49 Server Ready
This string tells you that the company is successful. The response of different servers will be different, but the beginning is the same, that is: " OK". It means that the server accepts the order and syntax used by the client computer. If the beginning is "-err", you indicate that you use the wrong command. In your application, only a few characters from the response from the server are required. Such a small processing is the advantage of POP3 relative to other protocols.
Authorized state
Ok, now we have established a connection with the server and get a positive answer from the server. The next thing to do is to tell the server your identity. The server should manage thousands of mailboxes is not difficult. It has established an account for each mailbox. Each account consists of a username and password. When you connect the server, the first command to send is user, the username is the parameter of the command. The specific way is as follows:
User Username
If the user name is registered, the server will return a correct message, then you can enter the following command to tell the server your password.
Pass Password
If the username and password are consistent, the server will return a correct message, telling you to go to the next phase, the Transaction State.
Transaction status
In order to know how many emails in your mailbox and these messages are available, you can use the STAT command. It will tell you the current state of the mailbox. The information returned by the server may be the following:
OK 0 0 (there is no email in your mailbox) OK 3 825 (there are three emails in your mailbox, the size is 825 eight bytes)
If there is no email in the mailbox, there is nothing to do, and you can end the connection with the server with the quit command. If you have an email in the mailbox, you can download the email to your own machine with the retrial command. This command requires an index of the message as its parameters. For example, if we want to receive the first email, enter the following command:
Retr 1
To retrieve other emails, use the above command to add the appropriate mail number. If the mail number you entered exceeds the number of emails in the mailbox, the server will return a "-err" for you. As a response to the Retri command, the server will return to you a string. This string contains the following: " OK", mail size, mail text, and a string containing a decimal point. The last string is that the decimal point indicates the end of the message. For example: Client: Retr 2 Server: OK 234 OCTETS Server:
Note that the process of receiving the mail above does not mean transferring these messages to your computer. You are a copy of these messages, and these messages will still be stored in your cash box until you use the dele command to remove them. Similarly, the dele command also requires you to provide an email index number. In fact, these messages are not immediately deleted from the server when you use the Dele command. These messages are just a deleted tag that is really deleted from the server when you disconnect the server. If you want to remove these delete tags, use the Rset command. This command is not for a specific message, but removes all delete tags, so you don't need to provide mail index marks to this command.
In addition to the commands mentioned above, POP3 also supports two other commands when you are still in the TRANSACTION state. These two commands are: List and NOOP. The list command can be used to list information. Just like the same below:
Client: List Server: OK 2 Messages (320 OCTETS) Server: 1 120 Server: 2 200 Server:.
Provide information on specific mail by providing mail index marks to the list command, such as the following example:
Client: List 2 Server: OK 2 200
The NOOP command is not done, just use to check the connection with the server.
Update status
When you are in an UPDATE state, you only have one command, that is: quit. Use this command to confirm all changes you have done, delete messages that delete tags and turn it off.
Other POP3 commands
The POP3 protocol also supports three other commands: Top, UIDL, and APOP. Here is only the first command. The TOP command can be used to get the header and the predefined string. This command is especially useful if a volume in your mailbox is large. With the TOP command, you can only display the message of the message header, and find the authors of the mail. You can even download this part of this information. The syntax of this command is as follows:
TOP MSG N
MSG - Mail's index number
N - number of rows you want to display
If there is an attachment,
Content-Type: Multipart / Mixed; Boundary = "---- = _ nextpart_000_01bc2b74.89d1ccc0 optional accessories
Content-type: multipart / alternative; bside = "---- = _ nextpart_000_047b_01c47be9.894d7dd0
HTML mail
Content-type: text / html; charSet = "GB2312"
Attachments are separated by a Buoundary string in the email, the last one has the end.