One of the requirements in a recent project was to give clients the ability to login to any email account from within our application. Email accounts generally use two RFC standards:
- RFC 1730 – IMAP
- RFC 1939 – POP
Its important to briefly understand the differences between the two. Think of IMAP (Internet Message Access Protocol) as a network folder where you have access to resources that do not physically reside on your local machine. IMAP never downloads any messages whereas POP (or post office protocol) on the other hand works by downloading email messages to the client’s machine.
Both protocols work with commands – you send commands and receive responses. I found this website useful for IMAP commands. You can check IMAP from a telnet console if you really want to.
With some basic knowledge of the two protocols and also knowing that GMail supports both, I started searching for some sample code. I found this library on CodeProject and found that the first library did not support SSL, which is a GMail requirement. I ended up on Codeplex and found that the library had been extended by someone else and that it included support for SSL. SSL stands for Secure Socket Layer and simply put means that the connection between the client and the server is secure. The solution on CodePlex comes with two C# projects, the library and a console application. The console application gives you a good place to practice and learn some IMAP commands. Once you get a basic understanding of these commands you can start writing web-based applications. Its important to understand that IMAP commands need to be given in a specific sequence. You first login, then you select a folder (INBOX) and then you can run FETCH commands to retrieve message data. Thats the easy part though, because once you get that data back you have to be able to parse the messages which requires a MIME (Multipurpose Internet Mail Extensions) parser. Introduce the Lumisoft Mime parser which parses almost everything.