How To Run An IMAP Server On Your WestHost VPS

IMAP is an Internet standard communications protocol which allows the user of a computer connected to the Internet to read email messages stored on a different computer. The precise definition of the IMAP protocol is contained in RFC 3501 . For a discussion of the design of IMAP, and for some software that supports it, see the University of Washington IMAP Information Center .

Installing

Use the WestHost Site Manager to install the IMAP server. This will have the additional effect of moving the mailbox files from /var/spool/mail to /var/spool/imap . The default POP3 server will still run and will still check /var/spool/mail/example for mail, but no incoming mail will actually be delivered there.

Screen grab of WestHost Site Applications indicating IMAP Server

Testing

The IMAP server listens on TCP port 143. For testing purposes, you can verify that it is now running by using a TELNET client program to access your VPS on that port:

% telnet example.com 143
Trying ddd.ddd.ddd.ddd...
Connected to example.com (ddd.ddd.ddd.ddd).
Escape character is '^]'.
* OK [CAPABILITY IMAP4REV1 LITERAL+ SASL-IR LOGIN-REFERRALS STARTTLS AUTH=LOGIN] example.com IMAP4rev1 2004.357 at Wed, 18 Jul 2007 09:08:20 -0600 (MDT)

Instead of making a TCP connection to port 143, you can use IMAP by using an ssh client to log in to the VPS and execute imapd on your VPS:

% ssh example@example.com exec /usr/local/imap-server-1.0/imapd
* OK [CAPABILITY IMAP4REV1 LITERAL+ SASL-IR LOGIN-REFERRALS STARTTLS AUTH=LOGIN] example.com IMAP4rev1 2004.357 at Wed, 18 Jul 2007 09:08:20 -0600 (MDT)

After you receive the initial response line * OK ... you can proceed to log in to the server and execute IMAP commands. If you do this using TELNET your username and password will be transmitted unencrypted over the Internet, which is a potential security hole. Using ssh protects your information by encrypting it.

Configuring

You probably want to protect your password by encrypting it when you send it to the IMAP server. One way to do this, using ssh, is shown above. Another way to do encryption is to use TLS to encrypt the TCP connection to port 143. The IMAP server does support TLS, but to use it you need to install a certificate.

When you connect to the IMAP server, you must log in to the server before you can access a mailbox. Note that if you execute imapd with ssh, you are logged in to the VPS but the ssh command does not automatically log you in to imapd - you must still do the IMAP login.

The standard default name of the primary mailbox is INBOX, according to RFC 3501 section 5.1. However, the primary mailbox supported by the IMAP server is named mbox, which is file /var/spool/imap/example/mbox . To access it you need to send the IMAP select mbox command to imapd after the IMAP login. You may be able to configure your mail user agent to reference mbox as the default mailbox. If your MUA does not offer this option, you can use the command line interface to your VPS to make the primary mailbox available by the standard name as follows:

cd /var/spool/imap/example
ln -s mbox INBOX

Last modified: Thursday, July 19 2007 at 8:47:17 AM MDT