The perfect email setup… for me

Email has always been a problem for me. Using web interfaces is a pain. Even the new JavaScript, single-page apps nowadays are bloated and slow. You can’t compare them to evolution, thunderbird or even outlook 🙂 Most Email Service Providers (ESPs) do provide POP3, but POP3 doesn’t support folders and is not a good option if you would like to access your mail from multiple locations.

So what is the solution? IMAP or the Internet Message Access Protocol gives me all the features I need:

  • Multiple clients simultaneously connected to the same mailbox

    I check my email from my Desktop, Laptop and PC at Uni.

  • supports folders

    can’t live without them. I don’t believe in labels, and virtual folders. I want to physically partition my mail.

  • Read/Write Support 2-way Synchronization

    I am not sure what this is really called but you know how POP3 supports downloading only? Well with IMAP you can upload emails to you mailbox. This also allows you to copy emails between folders or even accounts. It also allows you to do things like have your sent mail folder in your mailbox and have all your clients upload the sent mail there.

So what is the problem then? Most ESPs do not support IMAP. My old ESP ( did, but due to the stability issues of gawab, I had to look elseware.

Now I didn’t get your hopes up just to let you down! Remember that $5/month VPS I have? It is time to get some more use out of it!

The plan is to have an IMAP server on my VPS, I don’t want to have the responsibility of running a my own SMTP server, just the IMAP server. I would also like to consolidate my email addresses into one mailbox. This seams like a simple plan.. a good one too, if I don’t say so my self 🙂

Solving the SMTP Issue

So I don’t want the responsibility of running a SMTP server so I will pass the buck to google. Google Apps provides email for your domain so you don’t have to worry about 99.99% availability and all that.

Installing and Configuring the IMAP Server

I decided on Dovecot for the IMAP server because of it’s low memory footprint as well as it’s stability and good reputation.
in ubuntu all I needed was to:

apt-get install dovecot-imapd

I wanted to set up IMAP over SSL for better security so I needed to create a SSL certificate

cd /etc/ssl
openssl genrsa 1024 > private/domain.key
chmod 400 private/domain.key
openssl req -new -x509 -nodes -sha1 -days 365 -key private/domain.key > certs/domain.cert

I new that I planned to use a passwd like password file for authentication so I created one right away:

cat >>/etc/dovecot/passwd < <EOF

Then you need to configure dovecot by editing /etc/dovecot/dovecot.conf

protocols = imaps
## Logging
log_timestamp = "%Y-%m-%d %H:%M:%S "
## SSL settings
ssl_cert_file = /etc/ssl/certs/domain.cert
ssl_key_file = /etc/ssl/private/domain.key
## Login processes
login_user = dovecot
## Mailbox locations and namespaces
mail_location = maildir:/var/lib/mail/%d/%n
mail_extra_groups = mail
## Mail processes
first_valid_uid = 107
last_valid_uid = 107
## IMAP specific settings
protocol imap {
  login_greeting_capability = yes
## Authentication processes
auth_debug = yes
auth_debug_passwords = yes
auth default {
  mechanisms = plain
  user = root
  passdb passwd-file {
    # Path for passwd-file
    args = /etc/dovecot/passwd
  userdb static {
    args = uid=dovecot gid=mail domain=domain home=/var/lib/mail/%d/%u
## Dictionary server settings
plugin {

That's all

Consolidating my Email Accounts

I expected to have to learn the mysteries of fetchmail but I was lucky to find getmail4, a simpler replacement.

apt-get install getmail4
mkdir /etc/getmail
chown -R dovecot:mail /etc/getmail

create a getmailrc file /etc/getmail/domain-user that describes the retrieval and delivery phases
It will look something like:

type = SimplePOP3SSLRetriever
server =
username = user@domain
port = 995
password = your_password
type = Maildir
path = /var/lib/mail/domain/user/
delete = false
verbose = 0
delete_after = 0
read_all = false

test it with:

sudo -u dovecot getmail --getmaildir=/etc/getmail  --rcfile=/etc/getmail/domain-user

if all is OK then create a cron job to run say every 15 minutes

# Crontab for getmail. Download mail every 15 minutes
0,15,30,45 * * * *    dovecot getmail --getmaildir=/etc/getmail  --rcfile=/etc/getmail/domain1-user1
5,20,35,50 * * * *    dovecot getmail --getmaildir=/etc/getmail  --rcfile=/etc/getmail/domain2-user2

And there you have it! Just one nifty IMAP mailbox that contains all you email from all your accounts.

6 Responses to “The perfect email setup… for me”

  1. Mahmoud AlGammal Says:

    Read/Write support is better described as Two Way Synchronization 😉

  2. Ahmed Says:

    Thank you Mahmoud.

  3. Mahmoud Kassem Says:

    GMail added support for IMAP recently, but might not be available yet for all accounts, but it just got enabled on my account. Check your Settings Page for “Forwarding and POP/IMAP”

    Google POP3 gets your sent email messages too, so it might be a good idea to add a filter to move them to your sent directory if you still want to use Google POP3.

  4. Ahmed Says:

    Mahmoud Kassem:
    Using my setup, I don’t get sent mail! I would think that would only happen if you use the web interface to send email.

    As for IMAP… yep they have enabled it. I guess that kind of makes my setup obsolete 🙁

  5. Mahmoud Kassem Says:

    For sent mail:
    yes, you only get the sent messages from Google POP3 if you sent it from the web interface. they do not send you back what you sent from your mail client.

    But if you reset the google pop settings (get all messages), you will get everything again including the emails you previously sent from the mail client.

    For IMAP:
    quite better than POP3 specially because it updates the messages status on the web interface. with POP3 I end up with 100s of unread messages on the web. See:

  6. Ahmed Says:

    Mahmoud Kassem:
    Hmmm… I believe that I have arranged for email that I have downloaded via pop to be archived. So I don’t have that problem.

Leave a Reply