Easiest way to set up an IMAP mail server

You can use Dovecot for mail server

  1. Install the packages

    sudo apt-get install dovecot-imapd dovecot-pop3d

  2. Configure the protocol you need to be used by appending the protocol in the file /etc/dovecot/dovecot.conf:

    protocols = pop3 pop3s imap imaps

  3. Choose the mailbox you would like to use. Dovecot supports maildir and mbox formats. Edit the file /etc/dovecot/dovecot.conf and change the line

    mail_location = maildir:~/Maildir # (for maildir)

    or

    mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u # (for mbox)

  4. Restart the service

    sudo /etc/init.d/dovecot restart

  5. Use telnet to check that dovecot is working properly.

    telnet localhost imap

That's it.

PS. Also make sure your firewall is configured properly to accept connections on the appropriate ports.

Source : Official Dovecot Server Documentation