downloading emails via POP3 is an easy part of the task. The protocol is quite simple, and the advanced authentication methods can be the only difficult part if you do not want to send a text password over the network (and cannot use an SSL-encrypted communication channel). See RFC 1939: Mail Branch Protocol - Version 3 and RFC 1734: POP3 AUTHentication Command for details.
The tough part comes when you have to parse the received email, which means parsing the MIME format in most cases. You can write a fast and efficient MIME parser in a few hours or days, and it will process 95% of all incoming messages. Improving the parser so that it can parse almost any means of email:
- receiving email samples sent from the most popular email clients, and improving the analyzer to correct errors and misinterpretations of RFCs created by them.
- Make sure that messages that violate the RFC for message headers and content will not break your parser and that you can read every readable or valid value from a garbled message
- proper handling of internationalization issues (for example, languages โโwritten from righ to left, the correct encoding for a particular language, etc.)
- Unicode
- Attachments and the hierarchical tree of message items as shown in the Mime torture email example
- S / MIME (signed and encrypted letters).
- etc.
Debugging a reliable MIME analyzer takes many months. I know, because I watched my friend write one such parser for the component mentioned below, and wrote some unit tests for it; -)
Return to the original question.
Following the code taken from our POP3 Tutorial page and the links will help you:
// // create client, connect and log in Pop3 client = new Pop3(); client.Connect("pop3.example.org"); client.Login("username", "password"); // get message list Pop3MessageCollection list = client.GetMessageList(); if (list.Count == 0) { Console.WriteLine("There are no messages in the mailbox."); } else { // download the first message MailMessage message = client.GetMailMessage(list[0].SequenceNumber); ... } client.Disconnect();
Martin Vobr Sep 19 '08 at 14:13 2008-09-19 14:13
source share