Fetching of emails from a POP3 server and serving via IMAP (Ubuntu)

One of the servers from which I download emails regularly doesn’t provide IMAP access. The obvious solution seemed to be install my own IMAP server and fetch emails from the original server via POP3.

After a brief research, I’ve decided to install Dovecot and getmail to accomplish the above.

First step was to install Dovecot:

sudo apt-get install dovecot-imapd

Then I followed instructions from Dovecot website, set the location of IMAP mail directories and configured it to use SSL connections only. I have also modified standard port in /etc/dovecot/dovecot.conf from 993 to a different one:

protocol imap {
ssl_listen = *:7777

Restarted Dovecot

sudo /etc/init.d/dovecot restart

and tested my first IMAP account using Thunderbird. As the SSL certificate I used on the server was self-signed, Thunderbird complained about it but that can be ignored and SSL certificate saved.

After that, I installed getmail:

sudo apt-get install getmail4

For each mailbox I wanted to download from a POP3 server, I defined a separate config file for getmail:

type = SimplePOP3Retriever
server = mailserver
username = user
password = pass

type = Maildir
path = ~/Maildir/

Note that emails will be saved into Maildir directory within home directory of a particular user. Maildir is also the format in which emails will be saved. This configuration works nicely with Dovecot when serving emails.

The last step was to set up a cron job to fetch emails from POP3 and save them into IMAP folder:

crontab -e
* * * * * getmail -d >> getmail.log

where “-d” means it will delete messages from the server after downloading them.

getmail can also load multiple config files at once, so if you have more then one account to fetch:

getmail -d -r configfile1 -r configfile2

  1. No comments yet.

You must be logged in to post a comment.

  1. No trackbacks yet.