Debugging Mail Code

24. July 2010 Uncategorized 0

I’m working on a project that involves email and implementing RFCs for IMAP etc.  Normally I wouldn’t be keen to do something like this because I’d rather just grab an email library and write my functionality on top of that.  Normally I’d rant and rave about someone NOT doing it this way.  But for a few reasons that I won’t get into here, I’m not fortunate enough to have that opportunity. As I started on this project I realized this could actually be fun.  I now have to interact with servers that I have no control over.  I need to make sure I execute a LOGIN command correctly for IMAP and other similar methods.  However, as I sat out to implement this I realized I’d never interacted with an email server so I wasn’t sure what to expect.  Not to fear, I fired up google and found out you can actually telnet to the IMAP port on most mail servers and send commands and see what comes back. I ran into a couple roadblocks, though.  First, I’m not sure that gmail likes me actually telnetting in.  Even if they did, they require SSL for IMAP so I wasn’t sure if my errors were on my side or a bad implementation of SSL or something else.  This lead me to get my own email server.  After I installed this I was at least able to telnet to my local machine and play around with hMail’s implementation of IMAP.  This allows me to interact with a non-SSL implementation of a mail server. The next roadblock that I came across was not having any email in my mail server.  I was able to test out the command lines to create a new folder, but all of my interaction with the mail server returned 0 messages.  It’s hard to interact with messages when there aren’t any. The last step for my debugging was to open up hMail administrator, select my account and specify the external email information.  In my case, I just pointed it to pop access on gmail.  This let me download a few hundred messages.  Now I’m able to play around with my code and make sure that I’m getting the correct flow for IMAP.  After I nail that all down I can add the extra functionality for SSL (e.g. TLS).