Your Own Personal Mail Server
Are you sick of having all your mail spread arround on your computers? When you have more than one pc, or even if you check your email at work and then at home, it’s a nightmare to keep track of so many emails. And if you’re like me, I have multiple mail accounts, meaning more mail from diferent sources, well the solution isn’t spending all your day sending mail back and forward from one account to another. The solution is actually preety simple: IMAP!
This how to covers Ubuntu 6.06 Server (yes the server version of Ubuntu duh!) but it’s preety simple to adapt to other distros. Let’s start!
Be warned that you may loose some email messages in the process so test this first with a dummy account!
Assuming you have Ubuntu installed and updated, open a shell and type:
(create this on your home folder)
mkdir Maildir
sudo apt-get install dovecot
Let it install all the packages need for dependecies.
Dovecot is an open source IMAP and POP3 server, is very simple to install / configure and suports the Maildir format which is a standard and the one we’re going to use. Dovecot is very complete and has several options, most of them related to security, I’m not covering those so feel free to explore.
So, back to the shell and enter:
sudo nano /etc/dovecot/dovecot.conf
Now change the following:
# Protocols we want to be serving:
# imap imaps pop3 pop3s
#protocols = imap imaps
#protocols = imap imaps
to
# Protocols we want to be serving:
# imap imaps pop3 pop3s
#protocols = imap imaps
protocols = imap imaps
Save the file and run dovecot:
sudo /usr/sbin/dovecot
And now test your IMAP Server:
mutt -f imap://yourusername@localhost
You should get a little nagging about the certificates but after that you enter your password and you should be able to see your empty IMAP folder.
Now the next part is to get the email from the other accounts and for this we’re using a little app named Getmail. Getmail can check your POP and IMAP accounts, I’ll cover only the POP accounts but there’s some examples you can check. Getmail also features some very usefull mail sorting options you can check later.
So, if you’re using Ubuntu 6.06 “normal” then you should be able to download Getmail via apt-get:
sudo apt-get install getmail
If you’re using the Ubuntu server version you won’t get this package via apt-get unless you add the right repository or download the package and install it manually:
wget http://archive.ubuntu.com/ubuntu/pool/universe/g/getmail4/getmail4_4.4.3-1_all.deb
dpkg -i getmail4_4.4.3-1_all.deb
Now comes the lame part 😛
You’ll have to write a little configuration file for each of the POP / IMAP accounts you want to check. I’m going to give you an example for a regular POP account and for a GMAIL account.
Again, back to the shell and type:
cd
cd .getmail
touch gmailrc
sudo nano gmailrc
The configuration file for a GMAIL account:
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username = yourusername@gmail.com
password = yourpassword
[destination]
type = Maildir
path = ~yourhomedirectory/Maildir/
[options]
delete = true
Save it and repeat the process for a regular POP account:
touch ispmailrc
sudo nano ispmailrc
[retriever]
type = SimplePOP3Retriever
server = pop3.myisp.com
username = yourusername@myisp.com
password = yourpassword
[destination]
type = Maildir
path = ~yourhomedirectory/Maildir/
[options]
delete = true
Save and test it:
sudo /usr/bin/getmail --rcfile=gmailrc
If all goes well you’ll get a few messages like this:
getmail version 4.4.3
Copyright (C) 1998-2005 Charles Cazabon. Licensed under the GNU GPL version 2.
SimplePOP3SSLRetriever:username@gmail.com@pop.gmail.com:995:
0 messages retrieved, 0 skipped
This means Getmail is working, now send yourself some messages to your accounts to test it and run getmail again to check if it delivers to your IMAP folders. You can check it using Mutt like we did earlier.
By now everything should be working perfectly, we just have to automate the email checking. Let’s use crontab. Go to the shell and enter:
crontab -e
Now copy this line and save the file:
* * * * * /usr/bin/getmail --rcfile=gmailrc --rcfile=ispmailrc >> /dev/null 2>&1
(this has to be all in one line, don’t break it or it won’t work correctly!)
And we’re done! Now use an IMAP compatible client like Mozilla Thunderbir or Evolution and you’ll never have to worry with email again.
[tags]IMAP, POP, E-Mail, Email, GMail, Personal Mail Server, Linux, Ubuntu, Ubuntu Server, Getmail, Dovecot[/tags]
Nice! I was spending my time with Cyrus, but this is way simpler! Thanks!!!!
Great HOWTO. I’d been planning for a while to build a cyrus fetchmail procmail test setup to wrangle my email being spread across multiple accounts on multiple machines.
This approach seems a lot simpler. Thanks.
If you want to go the extra mile you can add postfix and squirrelmail and have webmail access to your imap folders.
And… if one of these days I need to change computer, I can just backup the ~/maildir follow this HOWTO again and move on, right?
I guess so… I never tried that but it’s supposed to work…
erkk i have an error on the last part
asialink@asialink-desktop:/usr/bin$ sudo /usr/bin/getmail –rcfile=gmailrc
Error: configuration file /home/asialink/.getmail/gmailrc does not exist
dunno where i did wrong…
I think you might skiped this part:
cd
cd .getmail
touch gmailrc
sudo nano gmailrc
[…] I thought that Getmail would be the best bet to collect the mail from the various hosts. I found this post which explained how to set up Getamil and […]
This is great! Just what I was looking for.
Could you change type to MDA_external, and process with procmail to do some filtering? Or should this be done on my actual computers where I read the mail?