August 24, 2013 @ 8:34 am, by Maarten Kossen
In light of recent events, there’s been a lot of chatter about leaving free e-mail services in favor of self-hosted e-mail. With self-hosted e-mail you have the option to host your e-mail wherever you want it, either on a server at home or on a VPS. Even my friend from Bennet Office Technologies told me to switch to a privately managed server to host my website and email.
There’s plenty of affordable options around to run your own mail server. I would personally recommend a Xen or KVM VPS for this, as with OpenVZ it is really easy for your provider to “snoop” on your e-mail. This is also possible with Xen or KVM, but it usually requires a reboot (which you will probably notice).
I’ve used a 512MB Xen VPS for this tutorial. I’ve used “this much” memory because I want to run clamd and SpamAssassin in RAM. The server also has 45GB of disk space, which is more than enough to run a couple of big mailboxes on. You could do with less RAM (though that would increase the CPU load and slow down mail processing) and far less disk space (depending on your needs), but with “my” specs, you’re on the safe side.
Installing Virtualmin
I’m using Virtualmin in this tutorial. The choice for Virtualmin is quite easy: it’s free, fast, stable and doesn’t invade your system (like, for example, cPanel does). Virtualmin may not have the prettiest UI out there, but it’s clean and it’s effective. You’ll only be using Virtualmin to create and administrate mailboxes. Other than that, you won’t need it.
Virtualmin has an open source (GPL) version and a commercial version. The commercial version has some “advanced” features not in the GPL version. I’ll be using the GPL version. This should run on most Linux distributions and FreeBSD.
So let’s install Virtualmin. I recommend a clean server for this, to avoid any conflicts. On the server, run:
wget http://software.virtualmin.com/gpl/scripts/install.sh
Which will get the installer script. Next, make it executable:
chmod +x install.sh
And finally, run the installer:
sudo ./install.sh
Which should ask you for your sudo password and if you’re sure you’re running the installer on a suitable system:
Next, it’s going to install a bunch of packages. Just sit back and relax. Get a cup of coffee or a beer. It could take anywhere from 5 tot 15 minutes (on average).
Once that is done, open a web browser and go to either your IP address or domain name on port 10000 with ‘https’ prepended:
https://192.0.2.1:10000
https://leb001.example.net:10000/
This should ask you to log in:
Use the username and password of your sudo user to log in. Once logged in, the post-installation wizard should appear:
Click ‘Next’. You will be asked whether to preload the virtualmin libraries or not and whether you want to run the email domain lookup server. I would recommend against the former, except if you have plenty of RAM. I would recommend turning on the domain lookup server for faster mail processing.
In the next step you can enable the ClamAV mail scanner server. I would really recommend enabling this.
The same applies to the SpamAssassin server filter in the next step. This one is easier on the memory than the ClamAV server or domain lookup server, so even in you choose not to enable those two, you should enable this one.
We don’t need MySQL or PostgreSQL running and sucking up memory. So disable both.
We don’t need bind, so tick the box to skip the resolvability check and leave the other fields the way they are.
Passwords should never, ever be stored in plain text, so only store hashed passwords.
Click ‘Next’ to go to the ‘System Information’ screen.
Which should look like this (don’t mind the yellow warning, we’ll get to that):
You’ve now successfully installed Virtualmin! Let’s configure it and create a mailbox.
Configuring services and adding your first mailbox
First, we need to configure some services. Go to ‘System Settings’ in the left menu and then to ‘Features and Plugins’. This is where we disable all services that are not related to serving e-mail. Untick all the boxes I have unticked in this screenshot:
When you click ‘Save’ you should return to the ‘System Information’ screen.
In the left menu, under ‘System Settings’, click ‘Re-Check Configuration’. This should check several things of your installation and display an error is something is wrong.
Let’s create a Virtual Server, so we can add a mailbox. Click ‘Create Virtual Server’ in the left menu:
Fill out the domain name for the server, which is the domain name you wish to receive e-mail for. Also pick a strong password. Click ‘Create Server’ to actually create the server:
Once your virtual server is up, let’s create a mailbox. Click ‘Edit Users’ in the left menu, which should open the user list:
Clicking ‘Add a user to this server’ opens the screen to create a new user. Because we disabled several features before, the user you’re going to create will only have an e-mail account. So, basically, you’re creating an e-mail account.
Fill out the e-mail address field, a real name and a strong password. Click ‘Create’ to finish this. You should be returned to the user overview, where you see your newly-created user including the IMAP/POP3 login.
And that’s it! You’ve just created your own e-mail server and your first mailbox!
To add your mailbox to an e-mail client, like Mozilla Thunderbird, your details will be (from the example above):
- Username: john.smith.example
- Password: the one you picked
- Mail server (IMAP/POP3/SMTP): the domain name/IP of the mail server
TLS is available but the certificate is self-signed, so you should accept the certificate to enable secure communication with the mail server.
The final step is to point you domain name’s DNS records to your newly created server, if you didn’t already. If your domain points to the server, point the MX record to your domain. If you’ve used a different domain for your server, point the MX record to that or the server IP. Once the DNS records have propagated, you should be receiving e-mail!
Final notes
This is one of the easiest ways to get a mail server running. You can improve your server by using a commercial SSL certificate (although, there is word those are not save from government eyes either) and install webmail software. Those are things for a future tutorial, however!
Your mail server also supports IMAP IDLE, which boils down to push for IMAP. This works especially well with K-9 Mail on an Android device or Mozilla Thunderbird (which both support IMAP IDLE). So, no loss leaving your free e-mail service here!
Up next week: Getting started with OpenVPN (tap)!
Comments