If you are working with more than one computer you might know this problem – your incoming and outgoing mails are spread over your several computers and often enough you have to search one specific mail on several machines.
To avoid that an IMAP-Mailbox with enough storage ist the best solution. But if you are not in the comfortable situation that someone has already done that for you, you might want to build one on your own.
I decided to use my Raspberry Pi to achieve that.
Of course there is more than one way to setup a mail-server with Linux, but after a while of trying my choice was getmail and dovecot.
For me the main advantage of getmail is, that you dont need a third-party-tool such as postfix to handle the Maildir-Format. And Maildir-Format is the first choice for my mailbox, because you can create subfolders from within your mail-client and store the incoming mail in those subfolders.
The plan is that getmail collects the emails from different mailboxes and stores them in the local mailbox of each user. Dovecot is then responsible for the delivery of the mails to the different users.
Then you can create a new mailbox in your mail client, where the incoming e-mail server is then the own server.
Credentials are then the user name and password that will be created.
Outgoing mail server remains the the SMTP server of your provider, such as Web.de or GMail.
So to get your little mailserver up and running you of course have to install the needed packages first.
( On a Rasperry Pi become user root with
sudo apt-get install dovecot-imapd getmail4
to install the packages.
Prepare user and group
After a fresh install only the user „root“ or „pi“ on a Raspberry are available. So to give different users each a own mailbox, these users need to be added.
For this type
root@server ~ # adduser USER Lege Benutzer »USER« an ... Lege neue Gruppe »USER« (9999) an ... Lege neuen Benutzer »USER« (9999) mit Gruppe »USER« an ... Erstelle Home-Verzeichnis »/home/USER« ... Kopiere Dateien aus »/etc/skel« ... Geben Sie ein neues UNIX-Passwort ein: Geben Sie das neue UNIX-Passwort erneut ein: passwd: Passwort erfolgreich geändert Benutzerinformationen für USER werden geändert. Geben Sie einen neuen Wert an oder drücken Sie ENTER für den Standardwert Vollständiger Name : Your Name Zimmernummer : Telefon geschäftlich : Telefon privat : Sonstiges : Sind die Informationen korrekt? [J/n]
Of course the name USER has to be replaced by the real name of the user.
Now create the mail directory for every user and set the right permissions:
mkdir /home/USER/Maildir chown -R USER:mail /home/USER/Maildir chmod -R 770 /home/USER/Maildir
If dovecot is installed it has no group by default. So to give dovecot the rights that it needs to handle your mailbox correctly you should add a group, that dovecot will belong to – lets say the group ‚mail‘.
So create the group ‚mail‘ first with the command
sudo groupadd mail
If the group already exist you will get a notification.
Then dovecot needs to be added to this group with
sudo usermod -G mail dovecot
After that you have to make some changes in the config file of dovecot, so that dovecot knows, where the mail is stored. To do so type
In that file add or uncomment the following lines:
listen = * mail_location = maildir:~/Maildir:LAYOUT=fs mail_access_groups=mail
With these lines you tell dovecot, that it has to listen on every incoming IPv4 connection, that the folder of the stored mails is in the users home directory ( ~ ) and is named Maildir, that the mails have to be stored in the maildir-format and that it belongs to the system-group mail.
This is all we have to do with dovecot.
Now getmail needs to be configured.
All getmail configuration occurs in the .getmail/ folder of the user’s home directory. The configuration is stored in a resource-file. If you have multiple accounts, define each account in a seperate file in the ~/.getmail/ directory. The resource-files can be named as you like. Create the required directories and set their permissions with the following commands:
mkdir ~/.getmail/ chmod 700 ~/.getmail/
And now lets define a resource file, for example for a google-account.
Create the file with
and add the following lines.
[retriever] type = SimplePOP3SSLRetriever server = pop.gmail.com port = 995 username = your-user-name password = your-password [destination] type = Maildir path = ~/Maildir [options] delete = true verbose = 1
A full documentation of the resource-files can be found here
After saving the file you can test your configuration with the command
getmail --rcfile myGoogleAccount
If everything went right you should see something like this
getmail version 4.xxx.xxx Copyright (C) 1998-2012 Charles Cazabon. Licensed under the GNU GPL version 2. SimplePOP3SSLRetriever:email@example.com:995: 0 messages (0 bytes) retrieved, 0 skipped
After testing set the verbose-level to 0 (verbose = 0) in your resource file to avoid any output.
Unfortunately getmail does not run as a daemon, so to run getmail every x minutes you will have to create a cron-job.
So to edit the CRon-Table of the user USER you need to become USER with the command
su - USER
To create the cron-job use the command
This will open your crontab in your default text-editor.
So to fetch your new Mail every 10 minutes add the following line
*/10 * * * * getmail --rcfile myGoogleAccount (--rcfile anOtherAccount)
Usually on a Raspberry or a Beaglebone the crontab should have opend in the text-editor Nano. So type strg+o for saving the crontab and close the editor with strg+x.
A more detailed description of cron can be found here
Now save the file and your job is done.