| Personal email server: Ubuntu, Maildrop, Zarafa |
|
On this page I describe how I setup my own mail server for personal use Warning: Use the information on this website at your own risk. It works for me, but it might not work for you.. Warning 2: You will need some proficiency with Linux and especially the Linux command line to be able to use the information on this website.Why have your own mail server?I wanted to have my own mail server, for a number of reasons:
DesignI decided to build my mail server on a small Intel Atom powered PC. Linux was the obvious OS for me, because it is open source and there is a lot of software available to enable such a setup. Furthermore I was already familiar with Linux. I chose Ubuntu as the Linux distribution for this server, as I am already familiar with Ubuntu setup and tools and I like it. Ubuntu 10.04 LTS was the obvious choice , as it was the latest and greatest at the time of writing this article. Based on previous experience, I picked the following software packages to build my email server:
InstallationI started by downloading the server edition of Ubuntu 10.04 LTS and using that to install Ubuntu on the harddisk. The questions during installation are rather straightforward. When chosing the software packages, I installed:
Additional softwareLet's first log in as root (super user) to further install and configure the server using the following command. sudo -i Now let's first bring our server up-to-date with this command aptitude safe-upgrade Let's install the tools to do get our email , do virus scanning and spam filtering and deliver them. apt-get install getmail4 maildrop exim4 clamav-daemon clamassassin
#install spamassassin and some other packages for added functionality to spamassassin.
apt-get install spamassassin libnet-dns-perl libmail-spf-query-perl pyzor razor
Probably it will ask you to install some other additional packages as well... Well, now we need to configure all these tools and then we can install Zarafa. MaildropMaildrop will actually filter your email through the spam filter and the virus scanner and it can also sort the email for you, if you'd like. I could have used something like Amavis to do the email filtering, but I used Maildrop also previously for my email sorting and I know how it works. It is not really fast, but it's fast enought to cope with only my personal email. A common way to configure maildrop is by creating a .mailfilter file in the home directory of your Linux user. For example /home/jeroen/. The .mailfilter file could look like this: #let's first pass our email through the virus scan xfilter "/usr/bin/clamassassin" if ($SIZE <256000) { #and now through the spam filter xfilter "/usr/bin/spamassassin" } if(/^X-Virus-Status: Yes$/) { # if it's a virus, remove the email to "/dev/null" } if(/^X-Spam-Flag: YES$/) { #send spam email to a special folder in my inbox. to "|/usr/bin/zarafa-dagent jeroen -F spam -s" # in the latest versions of Zarafa this is not necessary anymore, as the zarafa dagent itself will also look for the X-Spam-Flag header and put spam in the "Junk Mail Folder" } #if it's a normal email, send it to my Zarafa inbox to "|/usr/bin/zarafa-dagent jeroen -s" If you want to know more about maildrop, just use the maildrop manpages: man maildropor have a look at the website: http://www.courier-mta.org/maildrop/ SpamAssassinEven though SpamAssassin was already installed earlier on, it is not yet running. Under Ubuntu it is not enable by default. Go to /etc/default/spamassin and set
ENABLED=1
Furthermore I prefer the spam email not to be attached as an MIME attachment to a report email. I just want a spam header on the original message, such that Maildrop can then sort out what to do with the spam message.To enable this behaviour, you can go to /etc/spamassassin/local.cf and set
report_safe 0
In this file you can also change many other settings of SpamAssassin, but I just left it as it was.
As you might have noticed, the Bayesian classifier in SpamAssassin is by default enabled. But if you want the Bayesian classifier to be of any use, you will need to train it. I will get back to this later on.
GetmailIf you have maildrop setup, it's time to setup getmail to actually get your email. I execute getmail as my standard Linux user, not as root. To tell getmail where it should download the email, you'll have to create a folder called ".getmail" in your Linux user home directory. In this folder you create a file for each account that you have, named like getmailrc0, getmailrc1, getmailrc2, getmailrc3, etc. Use exactly this naming convention, otherwise getmail will not be able to find your account details. I will give an example for getmailrc0: [retriever] type = SimplePOP3Retriever server=pop.youremailserver.com username=yourusername password=yourpassword [destination] type = MDA_external path= /usr/bin/maildrop user=jeroen group=jeroen [options] #I want to keep the email on the POP server for 21 days before removing it delete_after=21 # don't download all the email every time, only download the email I haven't downloaded yet. #This is important if you don't delete your email from the POP server immediately read_all=false #Don't add a new Received header to the email, but use the existing Received header received=falseYou can find more information about getmail at : http://pyropus.ca/software/getmail/ Installing ZarafaStart by downloading the latest version of Zarafa from their website at http://www.zarafa.com/download-zarafa. At the time of writing Zarafa 6.40 was just released, so I installed that one. If you would like to use Outlook and the need the MAPI support, download the version with 3 users Outlook support. Unpack the zarafa installation files using something like: tar -xzf zarafa-6.40.0-ubuntu10.04-i386.tar.gzIn the folder where you just unpacked all the files is a install.sh file. Run it like: ./install.shand it will guide you through the entire installation process of zarafa. It will also setup the MySQL database for Zarafa and install dependencies if there are any. You can still change settings to the Zarafa server in /etc/zarafa/server.cfg once you completed the installation. Because I prefer the attachments to be stored outside the MySQL database, I set : attachment_storage = files. Don't forget to restart the server after you made any changes. The first testWebaccess for zarafa should be up and running now. You can test it by going to http://yourservername/webaccess/ and this should bring up the webaccess screen for Zarafa. You can log in with your Linux user account.But ofcourse your email inbox is still empty... Let's do something about that. Getmail get's your emailI made the following small script that can be executed by crontab. It will actually download your email and it should end up in your Zarafa inbox. getmail.sh : setlock -n /tmp/getmaillock getmail --getmaildir=/home/jeroen/.getmail --rcfile getmailrc0I used setlock to make sure there can only be one instance of the script active. Otherwise when the script is already running and the crontab already starts it again, a second instance of getmail is running and that might give errors and strange behaviour. Setlock is not standard installed, install "daemontools" with apt-get to get it installed. Also make sure the /tmp folder is writable for the user executing this script. Execute the getmail.sh script with your regular Linux user (the one you also use for the Zarafa email access), not with root. If everything goes well, you should see getmail downloading your emails. Once the script is finished, you can log in to the Zarafa webaccess again to see whether it has succesfully delivered the emails to your Zarafa inbox. Using Outlook to access your emailIf you would like to use Outlook to connect to your Zarafa server, you first need to install the Zarafa Client (which is a kind of a plugin for Outlook. This can be downloaded from http://www.zarafa.com/download-zarafa Zarafa comes also with good documentation, for both the server administrator as well as a user manual. These can be found at http://www.zarafa.com/content/documentationZarafa backup scriptI wanted a simple script to backup all my email to a NAS (Network Attached Storage) on my network. This NAS is already mounted as a NFS share on my Linux server. I use the following script to make a complete backup of all my email on the Zarafa server. First I make a dump from the Zarafa database on the MySQL server and then I make a backup of all the attachments seperately. echo "Zarafa email backup" # Setup variables for the archive filename. day=$(date +%A) daynumber=$(date +%u) name="$daynumber-$day" echo "name = $name" if [[ ! -e /mnt/backup/Email/zarafa/$name/ ]] then mkdir /mnt/backup/Email/zarafa/$name/ fi echo "Creating zarafa MySQL dump" mysqldump --single-transaction -uzarafa -pmyownpassword zarafa > /mnt/backup/Email/zarafa/$name/zarafa.sql #now create a tar.gz file of all attachments echo "Creating zarafa attachments tar" tar -czf /mnt/backup/Email/zarafa/$name/attachments.tar.gz -C /var/lib/ zarafaI run this script on a regular basis using cron.Warning: Executing this script might take a long time to complete if you have a lot of email and attachments.I run it at night, when not much else is going on on the server anyway.In this time period I don't run the getmail script, because if new mail comes in while making the backup, the MySQL dump and the attachments file might be out of sync. More information will be added. Please check back soon! |
Copyright Jeroen Vennegoor op Nijhuis

Your personal email server