This article is the beginning of receiving email from VFP; this is complemented with the articles you have already seen about sending email from VFP. To be able to do this, we will have to use the POP3 protocol (Post Office Protocol 3).
As many of you already know, it is my habit to see how things really work. For this purpose, we will have to investigate about the POP3 protocol, to see how it works, what its commands are, how the server works, etc. Thus, we continue with this series of articles; in this case, it is about receiving emails without third-party products, using only VFP.
I want to note that if you understood how SMTP works, understanding POP3 will be quite easy.
Objectives
Like SMTP, POP3 is a protocol that exchanges text between the client and the server applications. For this purpose, POP3 uses a series of commands supported by the server, so that the client can ask for the list of messages that the user has, request a specific message, and even erase it. By default, POP3 is available on port 110.
The points that we will develop are:
Standard commands
As a first step, we will learn the standard commands that should be available in all POP3 servers, that allow us to download our messages from the server, which were previously sent there via the SMTP protocol.
With these basic commands, we can now interact with the POP3 server, to ask it whether there are new message, to download the messages, and even to delete them if we don't want them on the server.
Optional commands
The optional, or extended, commands allow us a greater control, and greater security, with the messages on the server.
Control the commands sent to the POP3 server
The method to control the messages that return from the POP3 server is more simplistic than with SMTP messages, since here we have only two variants, either it is good or it is bad; unlike SMTP, which has different error codes depending on the command sent.
USER ianni_roberto@server.com.ar +OK password required for user ianni_roberto@server.com.ar PASS 123456789 -ERR [AUTH] Authentication failed
As we can see, the result of the commands comes with the "+OK" or "-ERR", and a descriptive message.
Telnet conection
Just like SMTP, you can also consult POP3 with a simple telnet, and thus access the messages stored on the server. The problem, as we shall soon see, is to understand the email with telnet!
If we run the following command from a console, we will have the conection, and we can pass the commands which we have just seen.
C:\Telnet server.com.ar 110 <abcde123654fghi> USER ianni_roberto@server.com.ar +OK password required for user ianni_roberto@server.com.ar PASS 123456789 +OK STAT +OK 5 13150 LIST 1 +OK 2630 RETR 1 +OK Return-Path: <ianni_roberto@hotmail.com> Delivered-To: CI-ianni_roberto@server.com.ar Received: (qmail 2516 invoked from network); 31 Aug 2004 10:55:57 -0000 Received: from unknown (HELO postino9.prima.com.ar) (172.16.1.100) by cumeil13.int.prima.com.ar with SMTP; 31 Aug 2004 10:55:57 -0000 Received: (qmail 63214 invoked by uid 10006); 31 Aug 2004 10:55:57 -0000 Received: (Antivirus 0e1d36106fc2798aa1704741707bfb9c); 31 Aug 2004 10:55:57 -0000 Received: (qmail 63186 invoked from network); 31 Aug 2004 10:55:56 -0000 Received: from unknown (HELO hotmail.com) (64.4.47.34) by postino9.prima.com.ar with SMTP; 31 Aug 2004 10:55:56 -0000 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 31 Aug 2004 03:55:54 -0700 Received: from 201.254.49.143 by by9fd.bay9.hotmail.msn.com with HTTP; Tue, 31 Aug 2004 10:55:54 GMT X-Originating-IP: [201.254.49.143] X-Originating-Email: [ianni_roberto@hotmail.com] X-Sender: ianni_roberto@hotmail.com From: "Roberto Ianni" <ianni_roberto@hotmail.com> To: ianni_roberto@server.com.ar Bcc: Subject: Test POP3 Date: Tue, 31 Aug 2004 07:55:54 -0300 Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_4c56_2fea_2f76" Message-ID: <BAY9-F34pD0mApR0Hy900018e35@hotmail.com> X-OriginalArrivalTime: 31 Aug 2004 10:55:54.0449 (UTC) FILETIME=[16679C10:01C48F49] This is a multi-part message in MIME format. ------=_NextPart_000_4c56_2fea_2f76 Content-Type: text/plain; charset=iso-8859-1; format=flowed texto _________________________________________________________________ MSN Amor: busca tu ½ naranja http://latam.msn.com/amor/ ------=_NextPart_000_4c56_2fea_2f76 Content-Type: application/x-zip-compressed; name="Adjunto1.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Adjunto1.zip" UEsDBBQAAAAIAPM7cS5OisqexwAAADYEAAAHAAAAQXBwLmljb+2SsQrCMBCG /7SBbtJHyCQ+hoNQhaKv0kFwvcHBx8rQUfocPoCDW7xLKqaRUrC4+SWXy11L cuR+QCGDMSWEWwYs2ZdliFcKWOTseW/Y1mwK2n+jDCOQnyAKToakeLHWcsb5 AAAIAA1rci7kSbemvwIAAGkKAAALAAAAAAAAAAEAIAC2gR0XAABNYWlsSXRl bS5jc1BLBQYAAAAABwAHAJgBAAAFGgAAAAA= ------=_NextPart_000_4c56_2fea_2f76 Content-Type: application/x-zip-compressed; name="Adjunto2.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Adjunto2.zip" UEsDBBQAAAAIAGKotS6k8Xq7bQUAABsVAAAbAAAAWWFob29NYWlsQ2hlY2tl ci9mcm1ZTUMuZnJt3Vfrb9s2EP8eIP8Dp36YjcWqHpbjdEsBP1sDzgO1myyf AAAAYqi1LgAAAAAAAAAAAAAAABEAAAAAAAAAAAAQAP9B2yMAAFlhaG9vTWFp bENoZWNrZXIvUEsFBgAAAAAGAAYAygEAAAokAAAAAA== ------=_NextPart_000_4c56_2fea_2f76-- DELE 1 +OK QUIT +OK
As we can see, first we identify ourselves with the server, so that the server knows who is the user connected. Then, we check for the number of emails in our inbox; together with the number of messages, the server returns the number of bytes they use. Once we have done that, we request the first message with the command "RETR"; the server replies with the message "+OK" and then sends us the complete message which is saved on the server.
When we get the message back, we can see that it is no more and no less than the message we have been sending with SMTP, therefore, we can understand it clearly. Within the message, we find the originator, the recipient, the subject, etc. Also, we see that this email contains two attachments, separated by the "boundary" we learned about in SMTP.
Once we received the message, we delete it from the server with the "DELE" command, and then we disconnect.
Conclusion
At the first sight, it looks difficult to read a message with these characteristics. What we have to do is locate, one part at a time, what we want to see. As you can imagine, the program that receives this has to do the same "parsing" of the text, to understand one part at a time, and show it to us in a simple format; but we will see this later.