This guide will help you set up your own mail server while you learn how email transport and delivery works on the internet nowadays. I have maintained this guide since Debian Woody was released in 2002. Back then it took me weeks to get all the information I needed. Has that really been 16 years by now? Wow. Thank you all for your kind feedback and support – I would probably have discontinued this guide without you. And this is already the eigth edition.
BETA WARNING – I know that this tutorial for Debian Stretch is pretty late. My employer moved their office to a new location right after Debian Stretch was released and that took a lot of my time. The large amount of “fan mail” reminded me to keep writing though. 🙂 Usually I take the time to go through the guide from scratch, build a new mail server on a test domain and check if everything is working for a while before I let you waste your time. Let me be honest – this time I have not done that. If you find anything unclear, misleading or wrong then please add a comment and I promise to fix that as quickly as possible. There are also sections still in the making – about virus scanning, DKIM signing, mitigating brute force attacks and enforcing mail quotas. It will take a few days to get that done. Thanks for your patience.
- 2018-02-09 – added Apache configuration to access the rspamd web interface
I am publishing this guide without any commercial interest. It just makes me happy to see more and more leisure sysadmins leave public freemail providers and operate their own servers. If you feel you would like to return the favor you can easily make me happy by clicking on the donation link at the bottom of this page. And please respect the copyright. I have seen literal copies of my work on the internet by people even making money with it. That’s annoying.
So what will the mail server cost you? The only recurring costs you may face are for running your mail server and for renting a domain. Cheap virtual servers are usually available at around $5 / 5€ per month and have enough power to run a mail server for your friends and family. The software being used is completely free and open-source. You can even make money with it. After all it is called “ISPmail” (ISP = internet service provider). Are you a sysadmin and your employer needs a mail server for their 500 employees? Go with this guide.
What your mail server can do
- Receive emails on your domain(s).
- Filter out spam and malware.
- Send emails out to any other servers/domains on the internet. Connections will be encrypted when possible.
- Add cryptographic signatures (DKIM) to outgoing emails.
- Store as many emails for as many email addresses as you have disk space. Set limits (“quotas”) per user.
- Let your users fetch email using IMAP or POP3 and send email through your servers using SMTP.
- Allow users to manage server-based filter rules. Distribute incoming emails to different folders. Forward copies. Or send out-of-office notifications.
- Provide a webmail interface so users can access their emails securely from any location.
- Mitigate brute force attacks.
What you will need
- Linux experience. Preferably a Debian-derivative. No godlike skills required. But know your basics: navigating through the file system, editing files, watching log files and having basic understanding of DNS and SQL (SELECT, INSERT, rows, columns).
- Time. 2 hours to 2 days depending on your skills.
- A server that runs with Debian Stretch. 1 GB of RAM and a 20 GB disk is fine for your friends and family. Rent a cheap virtual server. Or use a decommissioned laptop. Other Linux distributions likely come with other versions of the software and have different default configuration – so your mileage may vary if you use anything else than Debian.
- A public IP address that does not belong to a range of typical ISP customers. You usually can’t operate the mail server from a dialup IP address at home because those IP ranges are globally blacklisted. Make sure that your IP address is not blacklisted before you start.
- An internet domain (or more) to receive emails for. You need to be able to set A, MX and TXT records for that domain.
- Patience. We will proceed slowly and after every step ensure that you made no mistakes. Don’t hurry and skip parts even if they appear confusing at first. If you get lost just submit your question at the bottom of any page throughout this guide and help is on the way.
What this is not about
If you are lazy or in a hurry or just don’t want to learn about mail servers then this guide is not for you. There are ready solutions like iRedMail that you may want to consider. Running a mail server requires a certain technical understanding. And that’s what the ISPmail guide is for. Experience from giving support to other sysadmins shows that most problems appear because some detail in a complex setup goes wrong and they have no idea how to track it down. Email has evolved a lot over the past 40 years. Go with ready solutions if you like. But I have a feeling that we meet again. And you will probably not save time either taking the easy route. Or as one of the first long-haired nerds put it…
Everything should be made as simple as possible, but no simpler.
The whole tutorial is split into several pages. Please use the links on the right side to navigate through the pages. Make sure you have the server, a non-blacklisted IP and a domain ready. Let’s go.